Spaces:
Sleeping
Sleeping
Download utils/security.py from Arclen/mm-backend: direct link, hf CLI and curl.
- Browser
- Download file 881 Bytes
-
https://huggingface.co/spaces/Arclen/mm-backend/resolve/main/utils/security.py
- Command line
-
hf download hf://spaces/Arclen/mm-backend/utils/security.py
-
curl -L -o security.py https://huggingface.co/spaces/Arclen/mm-backend/resolve/main/utils/security.py
881 Bytes
| from passlib.context import CryptContext | |
| from datetime import datetime, timedelta | |
| from jose import jwt | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| SECRET_KEY = os.getenv("SECRET_KEY", "your_secret_key_change_in_production") | |
| ALGORITHM = "HS256" | |
| ACCESS_TOKEN_EXPIRE_MINUTES = 3000 | |
| # Updated scheme to match the seeding script | |
| pwd_context = CryptContext(schemes=["pbkdf2_sha256"], deprecated="auto") | |
| def verify_password(plain_password, hashed_password): | |
| return pwd_context.verify(plain_password, hashed_password) | |
| def get_password_hash(password): | |
| return pwd_context.hash(password) | |
| def create_access_token(data: dict): | |
| to_encode = data.copy() | |
| expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) | |
| to_encode.update({"exp": expire}) | |
| encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) | |
| return encoded_jwt | |