mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-11 03:20:24 +08:00
优化 login
This commit is contained in:
@@ -27,6 +27,7 @@ var (
|
|||||||
errWrongPassword = errors.New("invalid username or password")
|
errWrongPassword = errors.New("invalid username or password")
|
||||||
errTooManyFailedLogins = errors.New("too many failed logins")
|
errTooManyFailedLogins = errors.New("too many failed logins")
|
||||||
errAccountIsDisabled = errors.New("account is disabled")
|
errAccountIsDisabled = errors.New("account is disabled")
|
||||||
|
errUserTokenFull = errors.New("user token full")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -143,6 +144,14 @@ func login(username, challenge string) (*loginResult, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
token := base64.RawStdEncoding.EncodeToString(buf[:])
|
token := base64.RawStdEncoding.EncodeToString(buf[:])
|
||||||
|
cnt := 0
|
||||||
|
for usertokens.Get(token) != nil && cnt < 4096 {
|
||||||
|
token = base64.RawStdEncoding.EncodeToString(buf[:])
|
||||||
|
cnt++
|
||||||
|
}
|
||||||
|
if cnt >= 4096 {
|
||||||
|
return nil, errUserTokenFull
|
||||||
|
}
|
||||||
usertokens.Set(token, &user)
|
usertokens.Set(token, &user)
|
||||||
loginstatus.Store(username, loginStatusYes)
|
loginstatus.Store(username, loginStatusYes)
|
||||||
return &loginResult{
|
return &loginResult{
|
||||||
|
|||||||
Reference in New Issue
Block a user