- 新增 .gitignore:忽略备份、临时文件、IDE配置等 - 创建 backups/ 目录:存放数据库备份 - 创建 tools/ 目录:存放实用脚本(reset_passwords.py) - 移动文件到相应目录 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Reset all user passwords to 123456"""
|
|
|
|
import bcrypt
|
|
import mysql.connector
|
|
|
|
DB_CONFIG = {
|
|
'host': '8.148.151.56',
|
|
'port': 3306,
|
|
'user': 'root',
|
|
'password': 'reading_platform_pwd',
|
|
'database': 'reading_platform',
|
|
'charset': 'utf8mb4'
|
|
}
|
|
|
|
def main():
|
|
print("=" * 60)
|
|
print("Reset All User Passwords to '123456'")
|
|
print("=" * 60)
|
|
|
|
# Generate BCrypt hash for 123456
|
|
password = "123456"
|
|
salt = bcrypt.gensalt(rounds=10)
|
|
password_hash = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
|
|
|
|
print(f"\nNew BCrypt hash for '123456':")
|
|
print(f"{password_hash}")
|
|
print()
|
|
|
|
conn = mysql.connector.connect(**DB_CONFIG)
|
|
cursor = conn.cursor()
|
|
|
|
# Update admin_users
|
|
print("Updating admin_users...")
|
|
cursor.execute("UPDATE admin_users SET password = %s", (password_hash,))
|
|
print(f" Updated {cursor.rowcount} rows")
|
|
|
|
# Update tenants
|
|
print("Updating tenants...")
|
|
cursor.execute("UPDATE tenants SET password = %s", (password_hash,))
|
|
print(f" Updated {cursor.rowcount} rows")
|
|
|
|
# Update teachers
|
|
print("Updating teachers...")
|
|
cursor.execute("UPDATE teachers SET password = %s", (password_hash,))
|
|
print(f" Updated {cursor.rowcount} rows")
|
|
|
|
# Update parents
|
|
print("Updating parents...")
|
|
cursor.execute("UPDATE parents SET password = %s", (password_hash,))
|
|
print(f" Updated {cursor.rowcount} rows")
|
|
|
|
conn.commit()
|
|
|
|
print()
|
|
print("All passwords reset to '123456' successfully!")
|
|
|
|
cursor.close()
|
|
conn.close()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|