ERP/test_py/reset_all_passwords.py
2025-11-25 10:35:02 +08:00

77 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
批量重置所有用户密码
"""
import sqlite3
from werkzeug.security import generate_password_hash
DB_PATH = 'server/data.db'
# 默认密码设置
DEFAULT_PASSWORDS = {
'tz': 'tz123',
'张正浩': 'zzh123',
'admin': 'admin123',
'黄有想': 'hyx123'
}
def reset_all_passwords():
"""重置所有用户密码"""
try:
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
c = conn.cursor()
# 获取所有用户
users = c.execute('SELECT username FROM users').fetchall()
print("=" * 60)
print("🔐 批量重置用户密码")
print("=" * 60)
print()
for user in users:
username = user['username']
# 使用默认密码或统一密码
if username in DEFAULT_PASSWORDS:
new_password = DEFAULT_PASSWORDS[username]
else:
new_password = 'admin123' # 统一默认密码
# 生成新的密码哈希
password_hash = generate_password_hash(new_password)
# 更新密码
c.execute('UPDATE users SET password_hash = ? WHERE username = ?',
(password_hash, username))
print(f"{username:15s} | 新密码: {new_password}")
conn.commit()
conn.close()
print()
print("=" * 60)
print("✅ 所有密码已重置完成!")
print("=" * 60)
print()
print("📝 登录信息:")
print("-" * 60)
for username, password in DEFAULT_PASSWORDS.items():
print(f" 用户名: {username:15s} | 密码: {password}")
print()
print("💡 请使用上述账号密码登录")
print(" 登录地址: http://localhost:5000/login.html")
print()
except Exception as e:
print(f"❌ 错误: {e}")
return False
return True
if __name__ == '__main__':
reset_all_passwords()