Skip to content
Merged
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
10 changes: 7 additions & 3 deletions core/orm/user_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func mustLoginDummyBcryptHash() string {
return string(h)
}

// AuthenticateLocalUser verifies login/password via ORM read on core.user.
// AuthenticateLocalUser checks login and active state, then bcrypt-compares the stored password hash.
// Search redacts password, so the hash written at setup is read directly.
func AuthenticateLocalUser(ctx context.Context, login, password string) (uid int, username, name string, err error) {
login = strings.TrimSpace(login)
if login == "" || password == "" {
Expand Down Expand Up @@ -69,7 +70,11 @@ func AuthenticateLocalUser(ctx context.Context, login, password string) (uid int
comparePasswordHash("", password)
return 0, "", "", ErrInvalidCredentials
}
hash, _ := match["password"].(string)
var hash string
userTbl := MustQuotedTableName("core.user")
if err := DB.QueryRowContext(ctx, `SELECT COALESCE(password, '') FROM `+userTbl+` WHERE id = $1`, id).Scan(&hash); err != nil {
return 0, "", "", err
}
if !comparePasswordHash(hash, password) {
return 0, "", "", ErrInvalidCredentials
}
Expand Down Expand Up @@ -150,4 +155,3 @@ func comparePasswordHash(storedHash, plain string) bool {
}
return bcrypt.CompareHashAndPassword([]byte(storedHash), []byte(plain)) == nil
}

Loading