ChangePassword updates the user's password
(ctx context.Context, oldPassword, newPassword string)
| 101 | |
| 102 | // ChangePassword updates the user's password |
| 103 | func (s *Service) ChangePassword(ctx context.Context, oldPassword, newPassword string) error { |
| 104 | // Get the current user |
| 105 | user, err := s.userStore.Get(ctx) |
| 106 | if err != nil { |
| 107 | return fmt.Errorf("failed to get user: %w", err) |
| 108 | } |
| 109 | |
| 110 | // Verify old password |
| 111 | valid, err := VerifyPassword(oldPassword, user.PasswordHash) |
| 112 | if err != nil { |
| 113 | return fmt.Errorf("failed to verify password: %w", err) |
| 114 | } |
| 115 | if !valid { |
| 116 | return ErrInvalidCredentials |
| 117 | } |
| 118 | |
| 119 | // Validate new password strength |
| 120 | if len(newPassword) < 8 { |
| 121 | return errors.New("password must be at least 8 characters long") |
| 122 | } |
| 123 | |
| 124 | // Hash new password |
| 125 | hashedPassword, err := HashPassword(newPassword) |
| 126 | if err != nil { |
| 127 | return fmt.Errorf("failed to hash password: %w", err) |
| 128 | } |
| 129 | |
| 130 | // Update password |
| 131 | if err := s.userStore.UpdatePassword(ctx, hashedPassword); err != nil { |
| 132 | return fmt.Errorf("failed to update password: %w", err) |
| 133 | } |
| 134 | |
| 135 | log.Info().Msg("Password changed successfully") |
| 136 | return nil |
| 137 | } |
| 138 | |
| 139 | // API Key Management |
| 140 |
nothing calls this directly
no test coverage detected