Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions server/handles/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (

var loginCache = cache.NewMemCache[int]()
var (
defaultDuration = time.Minute * 5
defaultTimes = 5
defaultDuration = time.Minute * 5
defaultTimes = 5
invalidLoginCredentialsMsg = "username or password is incorrect"
)

type LoginReq struct {
Expand Down Expand Up @@ -69,13 +70,13 @@ func loginHash(c *gin.Context, req *LoginReq) {
// check username
user, err := op.GetUserByName(req.Username)
if err != nil {
common.ErrorResp(c, err, 400)
common.ErrorStrResp(c, invalidLoginCredentialsMsg, 400)
loginCache.Set(ip, count+1)
return
}
// validate password hash
if err := user.ValidatePwdStaticHash(req.Password); err != nil {
common.ErrorResp(c, err, 400)
common.ErrorStrResp(c, invalidLoginCredentialsMsg, 400)
loginCache.Set(ip, count+1)
return
}
Expand Down
Loading