-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
25 lines (17 loc) · 704 Bytes
/
utils.py
File metadata and controls
25 lines (17 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from passlib.hash import pbkdf2_sha256
from itsdangerous import URLSafeTimedSerializer
from flask import current_app
def hash_password(password):
return pbkdf2_sha256.hash(password)
def check_password(password, hashed):
return pbkdf2_sha256.verify(password, hashed)
def generate_token(email, salt=None):
serializer = URLSafeTimedSerializer(current_app.config.get('SECRET_KEY'))
return serializer.dumps(email, salt=salt)
def verify_token(token, max_age=(30 * 60), salt=None):
serializer = URLSafeTimedSerializer(current_app.config.get('SECRET_KEY'))
try:
email = serializer.loads(token, max_age=max_age, salt=salt)
except:
return False
return email