enable change password

This commit is contained in:
2026-09-10 09:47:57 +08:00
parent f10915e020
commit c841aa091d
5 changed files with 70 additions and 2 deletions

View File

@@ -984,6 +984,22 @@ class VideoRepository:
return None
return self.get_user_by_id(row["id"])
def set_user_password(self, username: str, password: str) -> bool:
"""Set a local password for either a normal or SSO-linked account."""
username = username.strip()
if not username:
return False
with self._connect() as connection:
cursor = connection.execute(
"""
UPDATE users
SET password_hash = ?
WHERE username = ? COLLATE NOCASE
""",
(hash_password(password), username),
)
return cursor.rowcount > 0
def create_session(self, user_id: str) -> str:
token = new_token()
now = datetime.now(timezone.utc)
@@ -1205,4 +1221,3 @@ def _is_cjk_char(char: str) -> bool:
or 0xF900 <= code <= 0xFAFF
or 0x20000 <= code <= 0x2CEAF
)