Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Aug 8, 2024
1 parent c964566 commit 68a4055
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def hash_osu_password(password: str) -> str:
).decode()


def check_osu_password(password: str, hashed_password: str) -> bool:
def check_osu_password(*, untrusted_password: str, hashed_password: str) -> bool:
return bcrypt.checkpw(
hashlib.md5(password.encode()).hexdigest().encode(),
hashlib.md5(untrusted_password.encode()).hexdigest().encode(),
hashed_password.encode(),
)

Expand Down
5 changes: 4 additions & 1 deletion app/usecases/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ async def authenticate(
user_feedback="Incorrect username or password.",
)

if not security.check_osu_password(password, user.hashed_password):
if not security.check_osu_password(
untrusted_password=password,
hashed_password=user.hashed_password,
):
return Error(
error_code=ErrorCode.INCORRECT_CREDENTIALS,
user_feedback="Incorrect username or password.",
Expand Down
10 changes: 8 additions & 2 deletions app/usecases/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ async def update_password(
user_feedback="User not found.",
)

if security.check_osu_password(user.hashed_password, current_password):
if security.check_osu_password(
untrusted_password=current_password,
hashed_password=user.hashed_password,
):
return Error(
error_code=ErrorCode.INCORRECT_CREDENTIALS,
user_feedback="Incorrect password.",
Expand All @@ -173,7 +176,10 @@ async def update_email_address(
user_feedback="User not found.",
)

if security.check_osu_password(user.hashed_password, current_password):
if security.check_osu_password(
untrusted_password=current_password,
hashed_password=user.hashed_password,
):
return Error(
error_code=ErrorCode.INCORRECT_CREDENTIALS,
user_feedback="Incorrect password.",
Expand Down

0 comments on commit 68a4055

Please sign in to comment.