API Users wit Cookies
Sorry for the wrong branch
This commit is contained in:
1 parent
8b70ed1550
commit
a36749d788
15 files changed
+494
-2
No files matched your search
@@ -0,0 +1,23 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import jwt
|
||||
from pwdlib import PasswordHash
|
||||
from pwdlib.hashers.argon2 import Argon2Hasher
|
||||
from config import settings #Settings from .env
|
||||
|
||||
|
||||
|
||||
password_hash = PasswordHash((Argon2Hasher(),))
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
return password_hash.hash(password)
|
||||
|
||||
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
||||
return password_hash.verify(plain_password, hashed_password)
|
||||
|
||||
def create_access_token(data: dict, expires_delta: timedelta | None = None) -> str:
|
||||
to_encode = data.copy()
|
||||
expire = datetime.now(timezone.utc) + (expires_delta or timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES))
|
||||
to_encode.update({"exp": expire})
|
||||
return jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
|
||||
|
||||
|
||||
Reference in new issue
Block a user