- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity.py
More file actions
Latest commit
12 lines (9 loc) · 506 Bytes
/
Copy pathsecurity.py
File metadata and controls
12 lines (9 loc) · 506 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
fromhmacimportcompare_digest#compare_digest returns a==b
frommodels.usermodelimportUserModel
defauthenticate(username, password):
user=UserModel.find_by_username(username)
ifuserandcompare_digest(user.password, password): #here, compare_digest checks that user password is the same as the password in authenticate func.
returnuser
defidentity(payload):
user_id=payload['identity'] #this contains the user's id saved into JWT
returnUserModel.find_by_id(user_id)