import sqlite3
import bcrypt

# 连接数据库
conn = sqlite3.connect('../backend/cmd/server/sale.db')
cursor = conn.cursor()

# 生成密码哈希
password = 'admin123'
hashed = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')

# 更新管理员密码
cursor.execute('UPDATE users SET password_hash = ? WHERE email = ?', (hashed, 'admin@viaeon.com'))
conn.commit()

# 验证更新
cursor.execute('SELECT email, password_hash FROM users WHERE email = ?', ('admin@viaeon.com',))
result = cursor.fetchone()

print(f"邮箱: {result[0]}")
print(f"密码哈希: {result[1]}")
print(f"密码已更新为: {password}")

# 测试密码验证
if bcrypt.checkpw(password.encode('utf-8'), result[1].encode('utf-8')):
    print("✅ 密码验证成功！")
else:
    print("❌ 密码验证失败！")

conn.close()
