Skip to content

Commit

Permalink
Calculate pw hash consistently with auth logic (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k authored Sep 13, 2024
1 parent fa64056 commit 5c1fb6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 2 additions & 3 deletions fixbackend/auth/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,9 @@ async def update(
if not user_update.current_password:
raise exceptions.InvalidPasswordException(reason="Current password is required to update password.")

db_pwd_hash = user.hashed_password
user_pwd_hash = self.password_helper.hash(user_update.current_password)
verified, _ = self.password_helper.verify_and_update(user_update.current_password, user.hashed_password)

if not secrets.compare_digest(db_pwd_hash, user_pwd_hash):
if not verified:
raise exceptions.InvalidPasswordException(reason="Current password is incorrect.")

return await super().update(user_update, user, safe)
Expand Down
4 changes: 3 additions & 1 deletion tests/fixbackend/auth/router_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from fixbackend.workspaces.models import WorkspaceInvitation
from fixbackend.workspaces.repository import WorkspaceRepository
from tests.fixbackend.conftest import InMemoryDomainEventPublisher, InsecureFastPasswordHelper
from fastapi_users.password import PasswordHelper


class InMemoryVerifier(AuthEmailSender):
Expand Down Expand Up @@ -156,11 +157,12 @@ async def test_registration_flow(
workspace_repository: WorkspaceRepository,
user_repository: UserRepository,
cert_store: CertificateStore,
password_helper: InsecureFastPasswordHelper,
user_manager: UserManager,
jwt_strategy: FixJWTStrategy,
fix_deps: FixDependencies,
) -> None:

user_manager.password_helper = PasswordHelper()
verifier = fix_deps.service(ServiceNames.auth_email_sender, InMemoryVerifier)
role_repo = fix_deps.add(ServiceNames.role_repository, InMemoryRoleRepository())
registration_json = {
Expand Down

0 comments on commit 5c1fb6e

Please sign in to comment.