修复旧哈希账号首次登录改密被要求原密码的问题

1. 登录时自动升级旧密码哈希改为只更新 password_hash,不再误清 need_change_password 标记
2. need_change_password 语义明确为"密码待修改":创建/重置置 1,用户改密成功清 0,登录自动升级哈希不影响
3. 首次登录弹窗与文档文案由"首次登录"改为"密码待修改(首次使用/被重置后)"
This commit is contained in:
canglan committed 2026-11-02 13:00:39 +08:00
1 parent f624219cba
commit 928c86bd5a
5 files changed
+31 -12

No files matched your search

+17
View File
@@ -102,6 +102,23 @@ class UserModel:
return True
exists = await execute_one("SELECT 1 FROM users WHERE user_id = %s", (user_id,))
return exists is not None
@staticmethod
async def upgrade_password_hash(user_id: int, password: str) -> bool:
"""仅升级密码哈希格式(bcrypt),不改变 need_change_password 标记
登录时自动升级旧哈希不等于用户主动改密,不能清除"密码待修改"标记。
"""
try:
password_hash = security.bcrypt_password(password)
except Exception as e:
logger.error(f"密码加密失败: {e}")
raise
result = await execute_update(
"UPDATE users SET password_hash = %s WHERE user_id = %s",
(password_hash, user_id)
)
return result > 0
@staticmethod
async def update_last_login(user_id: int, ip: str) -> None: