Skip to content

Commit d536062

Browse files
chore(auth): enhance password credential checks
1 parent 5a04f1e commit d536062

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pkg/auth/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,8 @@ func (s *authService) checkAndOfferPasswordSetup(
10371037
}
10381038

10391039
// Check if user already has password credentials
1040-
_, err := s.credentialsStorage.GetCredentials(ctx, email)
1041-
if err == nil {
1040+
credentials, err := s.credentialsStorage.GetCredentials(ctx, email)
1041+
if err == nil && credentials.PasswordHash != "" {
10421042
// User already has password, no need to send setup email
10431043
return
10441044
}

pkg/auth/api/password.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ func (s *authService) InitiatePasswordSetup(
170170
}
171171

172172
// Check if credentials already exist (user already has a password)
173-
_, err = s.credentialsStorage.GetCredentials(ctx, email)
174-
if err == nil {
173+
credentials, err := s.credentialsStorage.GetCredentials(ctx, email)
174+
if err == nil && credentials.PasswordHash != "" {
175175
// Password already exists, don't reveal this for security
176176
s.logger.Warn("Password setup attempted for account with existing password", zap.String("email", email))
177177
return &authproto.InitiatePasswordSetupResponse{
@@ -304,8 +304,8 @@ func (s *authService) SetupPassword(
304304
}
305305

306306
// Check if credentials already exist (prevent double setup)
307-
_, err = s.credentialsStorage.GetCredentials(ctx, setupToken.Email)
308-
if err == nil {
307+
credentials, err := s.credentialsStorage.GetCredentials(ctx, setupToken.Email)
308+
if err == nil && credentials.PasswordHash != "" {
309309
s.logger.Error("Setup attempted for account with existing password", zap.String("email", setupToken.Email))
310310
dt, err := auth.StatusPasswordAlreadyExists.WithDetails(&errdetails.LocalizedMessage{
311311
Locale: localizer.GetLocale(),
@@ -397,8 +397,8 @@ func (s *authService) ValidatePasswordSetupToken(
397397
email := ""
398398
if isValid {
399399
// Additional validation: check if account still needs password setup
400-
_, err := s.credentialsStorage.GetCredentials(ctx, setupToken.Email)
401-
if err == nil {
400+
credentials, err := s.credentialsStorage.GetCredentials(ctx, setupToken.Email)
401+
if err == nil && credentials.PasswordHash != "" {
402402
// Credentials already exist, token is no longer valid for setup
403403
isValid = false
404404
} else if !errors.Is(err, storage.ErrCredentialsNotFound) {

0 commit comments

Comments
 (0)