File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change
1
+ from werkzeug .security import generate_password_hash , check_password_hash
2
+
1
3
class User :
2
4
def __init__ (self , username , password ):
3
5
self .username = username
4
- self .password = password
6
+ self .password_hash = generate_password_hash (password )
7
+
8
+ def check_password (self , password ):
9
+ return check_password_hash (self .password_hash , password )
5
10
6
11
def __repr__ (self ):
7
12
return f"User(username={ self .username } )"
Original file line number Diff line number Diff line change @@ -70,6 +70,11 @@ def login_user(data):
70
70
if not data or "username" not in data or "password" not in data :
71
71
return jsonify ({"error" : "Username and password are required" }), 400
72
72
73
+ # Find user and validate credentials
74
+ user = next ((user for user in users if user .username == data ["username" ]), None )
75
+ if not user or not user .check_password (data ["password" ]):
76
+ return jsonify ({"error" : "Invalid username or password" }), 401
77
+
73
78
if auth_config .auth_method == AuthMethod .JWT :
74
79
access_token , refresh_token = generate_jwt_token (data ["username" ])
75
80
return jsonify ({
You can’t perform that action at this time.
0 commit comments