kindergarten_java/tools/reset_passwords.py

63 lines
1.6 KiB
Python
Raw Normal View History

#!/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()