MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / AuthenticateWithReason

Method AuthenticateWithReason

auth/user.go:515–553  ·  view source on GitHub ↗

AuthenticateWithReason returns true if the user exists, is not disabled, and has a valid password. If authentication fails, a user readable string for logging will be returned.

(password string)

Source from the content-addressed store, hash-verified

513
514// AuthenticateWithReason returns true if the user exists, is not disabled, and has a valid password. If authentication fails, a user readable string for logging will be returned.
515func (user *userImpl) AuthenticateWithReason(password string) (ok bool, reason string) {
516 if user == nil {
517 return false, "User not found"
518 }
519
520 // exit early for disabled user accounts
521 if user.Disabled_ {
522 return false, "Account disabled"
523 }
524
525 // exit early if old hash is present
526 if user.OldPasswordHash_ != nil {
527 // Password must be reset to use new (bcrypt) password hash
528 base.WarnfCtx(user.auth.LogCtx, "User account %q still has pre-beta password hash; need to reset password", base.UD(user.Name_))
529 return false, "User account still has pre-beta password hash; need to reset password"
530 }
531
532 // bcrypt hash present
533 if user.PasswordHash_ != nil {
534 if !compareHashAndPassword(cachedHashes, user.PasswordHash_, []byte(password)) {
535 // incorrect password
536 return false, "Incorrect password"
537 }
538
539 // password was correct, we'll rehash the password if required
540 // e.g: in the case of bcryptCost changes
541 if err := user.auth.rehashPassword(user, password); err != nil {
542 // rehash is best effort, just log a warning on error.
543 base.WarnfCtx(user.auth.LogCtx, "Error when rehashing password for user %s: %v", base.UD(user.Name()), err)
544 }
545 } else {
546 // no hash, but (incorrect) password provided
547 if password != "" {
548 return false, "Incorrect password"
549 }
550 }
551
552 return true, ""
553}
554
555// GetSessionUUID returns the UUID that a session to match to be a valid session.
556func (user *userImpl) GetSessionUUID() string {

Callers 1

AuthenticateMethod · 0.95

Calls 5

WarnfCtxFunction · 0.92
UDFunction · 0.92
compareHashAndPasswordFunction · 0.85
rehashPasswordMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected