File size: 1,373 Bytes
d29a5a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
"""Update admin user password with correct hashing."""

import sys
from pathlib import Path

# Add backend to path
sys.path.insert(0, str(Path(__file__).parent.parent))

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from app.modules.auth.service import security
from core.models.user import User


def update_admin_password():
    """Update admin user password with correct hashing."""
    database_url = f"sqlite:///{Path.home()}/.zenith/fraud_detection.db"

    engine = create_engine(database_url)
    session_local = sessionmaker(bind=engine)
    db = session_local()

    try:
        # Find admin user
        admin_user = db.query(User).filter(User.email == "admin@zenith.com").first()

        if not admin_user:
            print("❌ Admin user not found!")
            return

        # Update password with correct hashing
        admin_user.password_hash = security.get_password_hash("password123")
        db.commit()

        print("✅ Admin password updated successfully!")
        print(f"   User ID: {admin_user.id}")
        print(f"   Email: {admin_user.email}")
        print(f"   Role: {admin_user.role}")

    except Exception as e:
        print(f"❌ Error updating password: {e}")
        db.rollback()
    finally:
        db.close()


if __name__ == "__main__":
    update_admin_password()