Spaces:
Runtime error
Runtime error
Download app/core/security.py from AhmadYarAI/famfin-api: direct link, hf CLI and curl.
- Browser
- Download file 852 Bytes
-
https://huggingface.co/spaces/AhmadYarAI/famfin-api/resolve/main/app/core/security.py
- Command line
-
hf download hf://spaces/AhmadYarAI/famfin-api/app/core/security.py
-
curl -L -o security.py https://huggingface.co/spaces/AhmadYarAI/famfin-api/resolve/main/app/core/security.py
852 Bytes
| # app/core/security.py | |
| from datetime import datetime, timedelta | |
| from jose import jwt | |
| from passlib.context import CryptContext | |
| from app.core.config import settings | |
| import random | |
| pwd_context = CryptContext( | |
| schemes=["bcrypt_sha256"], | |
| deprecated="auto" | |
| ) | |
| def generate_otp(): | |
| return str(random.randint(100000, 999999)) | |
| def hash_password(p: str) -> str: | |
| return pwd_context.hash(p) | |
| def verify_password(plain: str, hashed: str) -> bool: | |
| return pwd_context.verify(plain, hashed) | |
| def create_access_token(data: dict, expires_minutes: int | None = None) -> str: | |
| to_encode = data.copy() | |
| expire = datetime.utcnow() + timedelta( | |
| minutes=expires_minutes or settings.ACCESS_TOKEN_EXPIRE_MINUTES | |
| ) | |
| to_encode.update({"exp": expire}) | |
| return jwt.encode(to_encode, settings.JWT_SECRET, algorithm=settings.JWT_ALGORITHM) |