Skip to content

Commit

Permalink
fix: treat empty string as nil in encrypted_password
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Jul 17, 2024
1 parent 85361b7 commit b48e0fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (a *API) ResourceOwnerPasswordGrant(ctx context.Context, w http.ResponseWri
return internalServerError("Database error querying schema").WithInternalError(err)
}

if !user.HasPassword() {
return oauthError("invalid_grant", InvalidLoginMessage)
}

if user.IsBanned() {
return oauthError("invalid_grant", InvalidLoginMessage)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ func (u *User) Authenticate(ctx context.Context, tx *storage.Connection, passwor

hash := *u.EncryptedPassword

if hash == "" {
return false, false, nil
}

es := crypto.ParseEncryptedString(hash)
if es != nil {
h, err := es.Decrypt(u.ID.String(), decryptionKeys)
Expand Down

0 comments on commit b48e0fa

Please sign in to comment.