Skip to content

Commit c310e9c

Browse files
authored
fix: verify old password only when non-empty (freeCodeCamp-2025-Summer-Hackathon#216)
1 parent 5fe1355 commit c310e9c

File tree

1 file changed

+3
-3
lines changed
  • backend/src/api/routes

1 file changed

+3
-3
lines changed

backend/src/api/routes/me.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fastapi import APIRouter, HTTPException
44

55
from src.api.dependencies import LoggedInUser
6-
from src.auth import User, get_password_hash
6+
from src.auth import User, get_password_hash, verify_password
77
from src.dependencies import Db
88
from src.models import Idea, IdeaPublic, IdeasPublic, UserEditPatch, UserMe
99

@@ -21,8 +21,8 @@ async def patch_me(
2121
current_user: Annotated[User, LoggedInUser],
2222
update_data: UserEditPatch,
2323
):
24-
if update_data.new_password is not None and update_data.old_password is not None:
25-
if get_password_hash(update_data.old_password) != current_user.hashed_password:
24+
if update_data.new_password and update_data.old_password:
25+
if not verify_password(update_data.old_password, current_user.hashed_password):
2626
raise HTTPException(status_code=403, detail="Invalid password")
2727
update_data.hashed_password = get_password_hash(update_data.new_password)
2828
current_user.model_update(update_data, exclude={"new_password", "old_password"})

0 commit comments

Comments
 (0)