e6d7888513
- python -m scripts.seed (module mode) fixes ModuleNotFoundError - Add scripts/__init__.py to make scripts/ a proper package - Generate initial Alembic migration for users table - Replace passlib with direct bcrypt>=4.0 (passlib unmaintained, broken with bcrypt 4.x) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
795 B
Python
29 lines
795 B
Python
from datetime import datetime, timedelta, timezone
|
|
|
|
import bcrypt
|
|
from jose import jwt
|
|
|
|
from app.core.config import settings
|
|
|
|
|
|
def hash_password(password: str) -> str:
|
|
return bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
|
|
|
|
|
|
def verify_password(plain: str, hashed: str) -> bool:
|
|
return bcrypt.checkpw(plain.encode(), hashed.encode())
|
|
|
|
|
|
def create_access_token(subject: str) -> str:
|
|
expire = datetime.now(timezone.utc) + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
|
return jwt.encode(
|
|
{"sub": subject, "exp": expire},
|
|
settings.SECRET_KEY,
|
|
algorithm=settings.ALGORITHM,
|
|
)
|
|
|
|
|
|
def decode_access_token(token: str) -> str:
|
|
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
|
return payload["sub"]
|