-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
46 lines (34 loc) · 1.17 KB
/
auth.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import bcrypt
from flask import session
def bind_user_to_session(user: object):
if user:
session.clear()
user_dict = {
'email': user.credentials['user_email'],
'password': user.credentials['user_password'],
'id': user.id,
'is_logged_in': 1,
'member_since': user.join_date
}
session["user"] = user_dict
session.modified = True
def bind_data_to_session_credentials(data: list):
user_credentials = {
'user-email': session['user']['email'],
'user-password': session['user']['password']
}
if data['new-password'] != '':
session['user']['password'] = data['new-password']
if data['user-email'] != '':
session['user']['email'] = data['user-email']
session.modified = True
return user_credentials
def hash_password(password: str):
salt = bcrypt.gensalt(rounds=16)
hased_pw = bcrypt.hashpw(password.encode('utf-8'), salt)
return hased_pw
def check_hashed_password(password: str, hashed_password: str):
if bcrypt.checkpw(password.encode('utf-8'), hashed_password):
return True
else:
return False