Skip to content

Commit 178f2d1

Browse files
authored
Merge pull request #9424 from okatu-loli/fix/auth-login-error-message
feat(auth): Add consistent error messaging for invalid login credentials
2 parents 225a675 + 3bc7de3 commit 178f2d1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

server/handles/auth.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import (
2626

2727
var loginCache = cache.NewMemCache[int]()
2828
var (
29-
defaultDuration = time.Minute * 5
30-
defaultTimes = 5
29+
defaultDuration = time.Minute * 5
30+
defaultTimes = 5
31+
invalidLoginCredentialsMsg = "username or password is incorrect"
3132
)
3233

3334
type LoginReq struct {
@@ -69,13 +70,13 @@ func loginHash(c *gin.Context, req *LoginReq) {
6970
// check username
7071
user, err := op.GetUserByName(req.Username)
7172
if err != nil {
72-
common.ErrorResp(c, err, 400)
73+
common.ErrorStrResp(c, invalidLoginCredentialsMsg, 400)
7374
loginCache.Set(ip, count+1)
7475
return
7576
}
7677
// validate password hash
7778
if err := user.ValidatePwdStaticHash(req.Password); err != nil {
78-
common.ErrorResp(c, err, 400)
79+
common.ErrorStrResp(c, invalidLoginCredentialsMsg, 400)
7980
loginCache.Set(ip, count+1)
8081
return
8182
}

0 commit comments

Comments
 (0)