This commit is contained in:
commit
279b2a7e90
49 files changed
+2664
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,20 @@
|
||||
import time
|
||||
|
||||
import jwt
|
||||
|
||||
from config import settings
|
||||
|
||||
JWT_SECRET = settings.jwt.secret
|
||||
JWT_ALGORITHM = "HS256"
|
||||
|
||||
|
||||
def generate_token(user_id: int) -> str:
|
||||
payload = {
|
||||
"user_id": user_id,
|
||||
"exp": int(time.time()) + 60 * 60 * 24,
|
||||
}
|
||||
return jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALGORITHM)
|
||||
|
||||
def decode_token(token: str) -> dict:
|
||||
payload = jwt.decode(token, JWT_SECRET)
|
||||
return payload
|
||||
@@ -0,0 +1,19 @@
|
||||
from argon2 import PasswordHasher
|
||||
from argon2.exceptions import InvalidHashError, VerifyMismatchError
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
ph = PasswordHasher()
|
||||
|
||||
hashed = ph.hash(password)
|
||||
|
||||
return str(hashed)
|
||||
|
||||
|
||||
def verify_password(password: str, hashed_password: str) -> bool:
|
||||
ph = PasswordHasher()
|
||||
|
||||
try:
|
||||
return ph.verify(hashed_password, password)
|
||||
except (VerifyMismatchError, InvalidHashError):
|
||||
return False
|
||||
Reference in new issue
Block a user