Spaces:
Sleeping
Sleeping
File size: 790 Bytes
0242ab2 | 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 | from datetime import datetime, timedelta
from jose import jwt
from passlib.context import CryptContext
from core.config import settings
pwd_context = CryptContext(
schemes=["bcrypt"],
deprecated="auto"
)
def hash_password(password: str) -> str:
return pwd_context.hash(password)
def verify_password(
plain_password: str,
hashed_password: str
) -> bool:
return pwd_context.verify(
plain_password,
hashed_password
)
def create_access_token(data: dict):
to_encode = data.copy()
expire = datetime.utcnow() + timedelta(
minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES
)
to_encode.update({"exp": expire})
return jwt.encode(
to_encode,
settings.SECRET_KEY,
algorithm=settings.ALGORITHM
) |