fix: cannot login with default password

This commit is contained in:
2026-07-20 11:30:25 +07:00
parent c8ebdb50b0
commit f3f1292aa4
5 changed files with 420 additions and 109 deletions
+4 -4
View File
@@ -60,7 +60,7 @@ def seed_admin():
conn = get_db_connection()
cursor = conn.cursor()
default_pwd = os.getenv("DEFAULT_ADMIN_PASSWORD", "admin123").strip()
default_pwd = (os.getenv("DEFAULT_ADMIN_PASSWORD") or "admin123").strip()
hashed_pwd = hash_password(default_pwd)
now = time.time()
@@ -79,9 +79,9 @@ def seed_admin():
""", (admin_id,))
conn.commit()
else:
# Guarantee admin account password hash matches default_pwd if must_change_password is true or hash doesn't match
if row["must_change_password"] or not verify_password(default_pwd, row["hashed_password"]):
cursor.execute("UPDATE users SET hashed_password = ? WHERE id = ?", (hashed_pwd, row["id"]))
# Kiểm tra và sửa password admin mặc định nếu cần
if not verify_password(default_pwd, row["hashed_password"]):
cursor.execute("UPDATE users SET hashed_password = ?, must_change_password = 1 WHERE id = ?", (hashed_pwd, row["id"]))
conn.commit()
conn.close()