Skip to content

Commit 6307242

Browse files
committed
Storing user secrets with passlib.
1 parent 59a5f66 commit 6307242

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

code/ch7-databases/db/pypi.sqlite

0 Bytes
Binary file not shown.

code/ch7-databases/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ starlette==0.13.6
99
SQLAlchemy==1.3.22
1010
progressbar2
1111
python-dateutil
12+
passlib
13+
1214

code/ch7-databases/services/user_service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Optional
22

3+
from passlib.handlers.sha2_crypt import sha512_crypt as crypto
4+
35
from data import db_session
46
from data.user import User
57

@@ -20,8 +22,7 @@ def create_account(name: str, email: str, password: str) -> User:
2022
user = User()
2123
user.email = email
2224
user.name = name
23-
# TODO: Set proper password
24-
user.hash_password = "TBD"
25+
user.hash_password = crypto.hash(password, rounds=172_434)
2526

2627
session.add(user)
2728
session.commit()
@@ -39,8 +40,7 @@ def login_user(email: str, password: str) -> Optional[User]:
3940
if not user:
4041
return user
4142

42-
# TODO: Verify password
43-
if False:
43+
if not crypto.verify(password, user.hash_password):
4444
return None
4545

4646
return user

0 commit comments

Comments
 (0)