# Imports from fastapi import HTTPException from sql import * from sqlmodel import select import hashlib def hash_password(password: str, salt: int = None): password = f"{password}{salt}" return hashlib.sha256(password.encode()).hexdigest() def verify_password(password: str, hash: str, salt: int) -> bool: hashed_pass = hash_password(password, salt) if hash == hashed_pass: return True return False def get_hero_by_email(email: str, session) -> Hero | None: return session.query(Hero).filter(Hero.email == email).first() def get_hero_by_id(id: str, session: SessionDep) -> Hero | None: statement = select(Hero).where(Hero.id == id) return session.exec(statement).first() def get_public_hero(id: int, session: SessionDep) -> HeroPublic: hero = session.get(Hero, id) if not hero: raise HTTPException(status_code=404, detail="Hero not found") return hero