Spaces:
Running
Running
Update auth_controller.py
Browse files- auth_controller.py +11 -2
auth_controller.py
CHANGED
@@ -14,12 +14,21 @@ async def login(request: Request):
|
|
14 |
password = data.get("password")
|
15 |
user = next((u for u in service_config.users if u["username"] == username), None)
|
16 |
if not user:
|
|
|
17 |
raise HTTPException(status_code=401, detail="Invalid username or password")
|
18 |
|
19 |
hashed = user["password_hash"].encode()
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
23 |
return {"message": "Login successful"}
|
24 |
|
25 |
@router.post("/change_password")
|
|
|
14 |
password = data.get("password")
|
15 |
user = next((u for u in service_config.users if u["username"] == username), None)
|
16 |
if not user:
|
17 |
+
log(f"β User '{username}' not found.")
|
18 |
raise HTTPException(status_code=401, detail="Invalid username or password")
|
19 |
|
20 |
hashed = user["password_hash"].encode()
|
21 |
+
log(f"π Checking password for user '{username}' with hash '{hashed}'.")
|
22 |
+
|
23 |
+
try:
|
24 |
+
if not bcrypt.checkpw(password.encode(), hashed):
|
25 |
+
log("β Password check failed.")
|
26 |
+
raise HTTPException(status_code=401, detail="Invalid username or password")
|
27 |
+
except Exception as e:
|
28 |
+
log(f"β Bcrypt check failed with error: {e}")
|
29 |
+
raise HTTPException(status_code=500, detail=f"Internal error during bcrypt check: {e}")
|
30 |
|
31 |
+
log(f"β
Login successful for user '{username}'.")
|
32 |
return {"message": "Login successful"}
|
33 |
|
34 |
@router.post("/change_password")
|