#!/usr/bin/env python3 """ Generate password hash for WHOOSH admin user Uses the same passlib configuration as the backend """ import subprocess import sys try: from passlib.context import CryptContext except ImportError: print("❌ passlib not installed. Installing...") subprocess.run([sys.executable, "-m", "pip", "install", "passlib[bcrypt]"]) from passlib.context import CryptContext # Same configuration as backend pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") # Generate hash for the new password password = "whooshadmin123" hashed = pwd_context.hash(password) print(f"Original password: {password}") print(f"Generated hash: {hashed}") # Verify it works verified = pwd_context.verify(password, hashed) print(f"Verification test: {'✅ PASS' if verified else '❌ FAIL'}") # Test against old password old_hash = "$2b$12$EjRUdYXNPgnveP6mgFY00uOj.fBp6u/9ZKqCZPdL4RK7QWg1Tpvp2" old_password_test = pwd_context.verify("whooshadmin", old_hash) print(f"Old password 'whooshadmin' verification: {'✅ PASS' if old_password_test else '❌ FAIL'}") new_password_test = pwd_context.verify("whooshadmin123", old_hash) print(f"New password 'whooshadmin123' against old hash: {'✅ PASS' if new_password_test else '❌ FAIL (expected)'}") print(f"\nSQL UPDATE command:") print(f"UPDATE users SET hashed_password = '{hashed}' WHERE username = 'admin';")