-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
37 lines (24 loc) · 785 Bytes
/
Copy pathauth.py
File metadata and controls
37 lines (24 loc) · 785 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
26
27
28
29
30
31
32
33
34
35
36
37
from datetime import datetime, timedelta, timezone
from config import settings
import jwt
from pwdlib import PasswordHash
password_hash = PasswordHash.recommended()
SECRET_KEY = "change-this-later"
ALGORITHM = "HS256"
def hash_password(password: str) -> str:
return password_hash.hash(password)
def verify_password(password: str, hashed_password: str) -> bool:
return password_hash.verify(password, hashed_password)
def create_access_token(data: dict, expires_minutes: int = 30):
to_encode = data.copy()
expire = datetime.now(timezone.utc) + timedelta(
minutes=expires_minutes
)
to_encode.update({
"exp": expire
})
return jwt.encode(
to_encode,
settings.SECRET_KEY,
algorithm=settings.ALGORITHM
)