-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_reset_password.py
More file actions
74 lines (60 loc) · 2.21 KB
/
quick_reset_password.py
File metadata and controls
74 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
"""
Quick password reset for local development.
Resets passwords for common accounts.
"""
import psycopg2
import bcrypt
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def reset_passwords():
"""Reset passwords for common accounts."""
# Get database connection from environment
db_url = os.getenv('DATABASE_URL', 'postgresql://postgres:postgres@localhost:5432/pythonide')
# Define accounts to reset with their new passwords
accounts_to_reset = [
('sa9082', 'password'), # Admin account
('sl7927', 'password'), # Another admin
('test_1', 'password'), # Test student
('test_2', 'password'), # Test student
]
try:
# Connect to database
conn = psycopg2.connect(db_url)
cur = conn.cursor()
for username, new_password in accounts_to_reset:
# Hash the new password
password_hash = bcrypt.hashpw(new_password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
# Update the password
cur.execute(
"UPDATE users SET password_hash = %s WHERE username = %s",
(password_hash, username)
)
if cur.rowcount > 0:
print(f"✅ Reset password for {username} -> '{new_password}'")
else:
print(f"⚠️ User {username} not found")
conn.commit()
print("\n🎉 Password reset complete!")
print("\n📝 You can now login with:")
for username, password in accounts_to_reset:
role = "Admin" if username in ['sa9082', 'sl7927'] else "Student"
print(f" {role}: {username} / {password}")
except Exception as e:
print(f"❌ Error resetting passwords: {e}")
finally:
if conn:
cur.close()
conn.close()
if __name__ == "__main__":
print("🔐 Quick Password Reset for Local Development")
print("=" * 50)
print("This will reset passwords for common test accounts.")
print("=" * 50)
response = input("\nDo you want to proceed? (yes/no): ").strip().lower()
if response == 'yes' or response == 'y':
reset_passwords()
else:
print("Cancelled.")