import psycopg2
import bcrypt
import os
from dotenv import load_dotenv

load_dotenv()

# New password for admin
new_password = "admin123"  # Change this to whatever you want

# Hash the password
salt = bcrypt.gensalt()
password_hash = bcrypt.hashpw(new_password.encode('utf-8'), salt).decode('utf-8')

# Update in database
conn = psycopg2.connect(os.getenv('DATABASE_URL'))
cur = conn.cursor()

# Update admin password
cur.execute(
    "UPDATE users SET password_hash = %s WHERE username = %s",
    (password_hash, 'admin')
)
conn.commit()

# Verify
cur.execute("SELECT username, email, is_admin FROM users WHERE username = 'admin'")
user = cur.fetchone()
if user:
    print(f"✓ Admin password updated successfully!")
    print(f"  Username: {user[0]}")
    print(f"  Email: {user[1]}")
    print(f"  Is Admin: {user[2]}")
    print(f"\nYou can now login with:")
    print(f"  Username: admin")
    print(f"  Password: {new_password}")
else:
    print("✗ Admin user not found!")

cur.close()
conn.close()
