#!/usr/bin/env python3 import sys import os import bcrypt sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) from sqlalchemy.orm import Session from src.config.database import SessionLocal from src.models.user import User from src.config.logging_config import setup_logging logger = setup_logging() def hash_password(password: str) -> str: password_bytes = password.encode('utf-8') salt = bcrypt.gensalt() hashed = bcrypt.hashpw(password_bytes, salt) return hashed.decode('utf-8') def reset_password(db: Session, email: str, new_password: str) -> bool: user = db.query(User).filter(User.email == email).first() if not user: print(f"āŒ User with email '{email}' not found") return False hashed_password = hash_password(new_password) user.password = hashed_password db.commit() db.refresh(user) print(f"āœ… Password reset for {email}") print(f" New password: {new_password}") print(f" Hash length: {len(user.password)} characters") print() return True def main(): db = SessionLocal() try: print("="*80) print("RESETTING TEST USER PASSWORDS") print("="*80) print() except Exception as e: logger.error(f"Error: {e}", exc_info=True) print(f"\nāŒ Error: {e}") db.rollback() finally: db.close() if __name__ == "__main__": main()