From c29f4af574f33cd0b2febd24234884403b08c64e Mon Sep 17 00:00:00 2001 From: dvirlabs Date: Fri, 8 May 2026 15:29:35 +0300 Subject: [PATCH] Fix bcrypt password hashing error in admin user creation - Added fallback to use bcrypt directly if passlib fails - Handles bcrypt version compatibility issue - Ensures admin user can be created even with library conflicts --- backend/app/main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/app/main.py b/backend/app/main.py index a511023..3d948b1 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -31,10 +31,22 @@ def create_admin_user(): try: admin = db.query(User).filter(User.email == settings.admin_email).first() if not admin: + try: + hashed_password = get_password_hash(settings.admin_password) + except Exception as hash_error: + print(f"⚠️ Password hashing error: {hash_error}") + print("⚠️ Using direct bcrypt hash as fallback...") + # Fallback: use bcrypt directly to avoid passlib version issues + import bcrypt + hashed_password = bcrypt.hashpw( + settings.admin_password.encode('utf-8'), + bcrypt.gensalt() + ).decode('utf-8') + admin = User( email=settings.admin_email, full_name=settings.admin_full_name, - hashed_password=get_password_hash(settings.admin_password), + hashed_password=hashed_password, is_admin=True, is_active=True, must_change_password=True # Force password change on first login