Skip to content

Commit

Permalink
auth: optimize lock scope in CheckPassword
Browse files Browse the repository at this point in the history
to improve authentication performance in concurrent scenarios when enable auth and using authentication based password
  • Loading branch information
wswcfan committed Mar 30, 2020
1 parent dd816f0 commit b7853d9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,26 @@ func (as *authStore) CheckPassword(username, password string) (uint64, error) {

tx := as.be.BatchTx()
tx.Lock()
defer tx.Unlock()

user := getUser(as.lg, tx, username)
if user == nil {
tx.Unlock()
return 0, ErrAuthFailed
}

if user.Options != nil && user.Options.NoPassword {
tx.Unlock()
return 0, ErrAuthFailed
}

revision := getRevision(tx)
tx.Unlock()

if bcrypt.CompareHashAndPassword(user.Password, []byte(password)) != nil {
as.lg.Info("invalid password", zap.String("user-name", username))
return 0, ErrAuthFailed
}
return getRevision(tx), nil
return revision, nil
}

func (as *authStore) Recover(be backend.Backend) {
Expand Down

0 comments on commit b7853d9

Please sign in to comment.