Spaces:
Building
Building
Update auth_controller.py
Browse files- auth_controller.py +0 -21
auth_controller.py
CHANGED
@@ -24,24 +24,3 @@ def login(request: LoginRequest, config: ServiceConfig = Depends(get_config)):
|
|
24 |
raise HTTPException(status_code=401, detail="Invalid username or password")
|
25 |
|
26 |
return { "status": "success" }
|
27 |
-
|
28 |
-
@router.post("/change_password")
|
29 |
-
async def change_password(request: Request):
|
30 |
-
data = await request.json()
|
31 |
-
username = data.get("username")
|
32 |
-
old_password = data.get("old_password")
|
33 |
-
new_password = data.get("new_password")
|
34 |
-
user = next((u for u in service_config.users if u["username"] == username), None)
|
35 |
-
if not user:
|
36 |
-
raise HTTPException(status_code=404, detail="User not found")
|
37 |
-
|
38 |
-
if not bcrypt.checkpw(old_password.encode(), user["password_hash"].encode()):
|
39 |
-
raise HTTPException(status_code=401, detail="Old password is incorrect")
|
40 |
-
|
41 |
-
new_hash = bcrypt.hashpw(new_password.encode(), bcrypt.gensalt()).decode()
|
42 |
-
user["password_hash"] = new_hash
|
43 |
-
|
44 |
-
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
45 |
-
json.dump(service_config, f, indent=2)
|
46 |
-
|
47 |
-
return {"message": "Password updated successfully"}
|
|
|
24 |
raise HTTPException(status_code=401, detail="Invalid username or password")
|
25 |
|
26 |
return { "status": "success" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|