fix: cannot login with default password
This commit is contained in:
+4
-4
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user