import hashlib from fastapi import APIRouter, HTTPException, Depends from fastapi.responses import JSONResponse from config import settings router = APIRouter(prefix="/api/auth", tags=["auth"]) _tokens: set[str] = set() def hash_password(pw: str) -> str: return hashlib.sha256(f"{pw}:livestream-salt".encode()).hexdigest() ADMIN_HASH = hash_password(settings.admin_password) @router.post("/login") async def login(password: str): if hash_password(password) != ADMIN_HASH: raise HTTPException(status_code=401, detail="Invalid password") token = hashlib.sha256(f"{password}:token".encode()).hexdigest() _tokens.add(token) return {"token": token} @router.post("/verify") async def verify(token: str): if token not in _tokens: raise HTTPException(status_code=401, detail="Invalid token") return {"valid": True}