Team Ai
Apppublic

ruby2210/todo-manager

sourceHugging Facemitupdated 9mo agoView on Hugging Face
0likes
security.py53 linesDownload Raw Back to core
1from passlib.context import CryptContext2from typing import Union3from datetime import datetime, timedelta4 5 6# Password hashing context7pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")8 9 10def verify_password(plain_password: str, hashed_password: str) -> bool:11    """12    Verify a plain password against a hashed password.13 14    Note: This is included for completeness but may not be used extensively15    since authentication is handled by Better Auth JWT tokens.16    """17    return pwd_context.verify(plain_password, hashed_password)18 19 20def get_password_hash(password: str) -> str:21    """22    Generate a hash for a plain password.23 24    Note: This is included for completeness but may not be used extensively25    since authentication is handled by Better Auth JWT tokens.26    """27    return pwd_context.hash(password)28 29 30def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):31    """32    Create access token with expiration.33 34    Args:35        data: Data to encode in token36        expires_delta: Token expiration time37 38    Returns:39        Encoded JWT token string40    """41    from datetime import datetime42    from jose import jwt43    from src.core.config import settings44 45    to_encode = data.copy()46    if expires_delta:47        expire = datetime.utcnow() + expires_delta48    else:49        expire = datetime.utcnow() + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)50 51    to_encode.update({"exp": expire.timestamp()})52    encoded_jwt = jwt.encode(to_encode, settings.BETTER_AUTH_SECRET, algorithm=settings.JWT_ALGORITHM)53    return encoded_jwt