Spaces:
Running
Running
File size: 723 Bytes
15ea62b 0359012 15ea62b 2f43b92 15ea62b 2f43b92 d67439e 955cb9c d67439e 955cb9c d67439e 4e4ad14 d67439e 955cb9c d67439e 955cb9c 0359012 | 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 | from passlib.context import CryptContext
from fastapi import HTTPException
from app.core.config import settings
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
ALGORITHM = "HS256"
SECRET_KEY = settings.SECRET_KEY
def get_password_hash(password: str) -> str:
"""
Hashes a password using bcrypt algorithm.
Truncates to 72 bytes for bcrypt compatibility.
"""
return pwd_context.hash(password[:72])
def verify_password(password: str, hash: str) -> bool:
"""
Verifies a password against a bcrypt hash.
Truncates to 72 bytes for bcrypt compatibility.
"""
is_valid = pwd_context.verify(password[:72], hash)
if not is_valid:
return False
return True
|