Skip to content

Commit c82d95b

Browse files
author
Uttam Singh
committed
Fix bcrypt byte limit in seed-admin
1 parent cc3f214 commit c82d95b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

backend/seed/admin.py.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ def seed_admin(db: Session = Depends(get_db)):
77
if existing:
88
return {"ok": True, "note": "Admin already exists"}
99

10+
# Fix bcrypt 72-byte password limit safely
1011
raw_password = "Edme@123"
11-
if len(raw_password.encode("utf-8")) > 72:
12-
raw_password = raw_password[:72]
12+
encoded = raw_password.encode("utf-8")
13+
if len(encoded) > 72:
14+
encoded = encoded[:72]
15+
safe_password = encoded.decode("utf-8", "ignore")
1316

1417
admin = User(
1518
name="Admin",
1619
email=email,
17-
hashed_password=bcrypt.hash(raw_password),
20+
hashed_password=bcrypt.hash(safe_password),
1821
department="Finance",
1922
role="admin",
2023
manager_email=None,
2124
)
2225
db.add(admin)
2326
db.commit()
24-
return {"ok": True, "note": "Admin created"}
27+
return {"ok": True, "note": "Admin created successfully"}
2528
except Exception as e:
2629
return {"ok": False, "error": str(e)}

0 commit comments

Comments
 (0)