ciyidogan commited on
Commit
f61a726
Β·
verified Β·
1 Parent(s): dc2e6d0

Update auth_controller.py

Browse files
Files changed (1) hide show
  1. 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
- if not bcrypt.checkpw(password.encode(), hashed):
21
- raise HTTPException(status_code=401, detail="Invalid username or password")
 
 
 
 
 
 
 
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")