Spaces:
No application file
No application file
File size: 653 Bytes
52d98a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# utils.py
from passlib.context import CryptContext
from jose import jwt
from datetime import datetime, timedelta
SECRET_KEY = "mysecret"
ALGORITHM = "HS256"
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
def hash_password(password: str):
return pwd_context.hash(password)
def verify_password(plain: str, hashed: str):
return pwd_context.verify(plain, hashed)
def create_token(data: dict, expires_minutes: int = 60):
data = data.copy()
expire = datetime.utcnow() + timedelta(minutes=expires_minutes)
data.update({"exp": expire})
return jwt.encode(data, SECRET_KEY, algorithm=ALGORITHM)
|