from flask_bcrypt import Bcrypt import mysql.connector # Initialize Bcrypt bcrypt = Bcrypt() # Database connection details MYSQL_HOST = '8.218.165.242' MYSQL_USER = 'sure_001' MYSQL_PASSWORD = 'EKKWLMmrGmG7sdPf' MYSQL_DB = 'sure_001' # Function to get database connection def get_db_connection(): return mysql.connector.connect( host=MYSQL_HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DB ) # Function to update admin password def update_teacher_password(teacher_id, new_plain_password): conn = get_db_connection() cursor = conn.cursor() # Generate new hashed password hashed_password = bcrypt.generate_password_hash(new_plain_password).decode('utf-8') # Update password in the database cursor.execute( 'UPDATE teachers SET password = %s WHERE id = %s', (hashed_password, teacher_id) ) # Commit changes and close the connection conn.commit() cursor.close() conn.close() # Example: Updating the password for admin with ID 1 if __name__ == "__main__": tid = 1 # The ID of the admin to update new_password = 'xiaoyan99817' # The new plain password you want to set update_teacher_password(tid, new_password) print(f"Password for admin with ID {tid} has been updated.")