fix(task7): invalidate tokens on password change or reset

This commit is contained in:
Atharv1705
2026-11-17 18:31:45 +05:30
parent b8639bc52a
commit 9276064d18
11 changed files with 145 additions and 4 deletions
+2
View File
@@ -180,6 +180,7 @@ def update_user(
if password is not None and password != "":
validate_password(password, email=data.get("email", user.email))
user.password_hash = hash_password(password)
user.token_version = (user.token_version or 0) + 1
for k, v in data.items():
setattr(user, k, v)
@@ -243,5 +244,6 @@ def reset_user_password(
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found.")
validate_password(payload.new_password, email=user.email)
user.password_hash = hash_password(payload.new_password)
user.token_version = (user.token_version or 0) + 1
db.commit()
return {"message": f"Password for {user.name} has been reset successfully."}