import sqlite3
from passlib.context import CryptContext

pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")

# 连接数据库
conn = sqlite3.connect('qa_system.db')
cursor = conn.cursor()

# 查询所有用户
cursor.execute("SELECT id, username, email FROM users")
users = cursor.fetchall()

print("当前用户列表：")
print("-" * 60)
for user in users:
    print(f"{user[0]}. 用户名: {user[1]}, 邮箱: {user[2]}")
print("-" * 60)

# 为所有用户重置密码为 "123456"
new_password = "123456"
hashed_password = pwd_context.hash(new_password)

for user in users:
    cursor.execute("UPDATE users SET hashed_password = ? WHERE id = ?", (hashed_password, user[0]))
    print(f"已将用户 '{user[1]}' 的密码重置为: {new_password}")

conn.commit()
conn.close()

print("\n密码重置完成！")
print(f"所有用户的密码都已重置为: {new_password}")
