25 lines
728 B
Python
25 lines
728 B
Python
# Imports
|
|
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) -> HeroPublic | None:
|
|
statement = select(Hero.email).where(Hero.email == email)
|
|
return session.exec(statement).first()
|
|
|
|
def get_hero_by_id(id: str, session: SessionDep) -> Hero | None:
|
|
statement = select(Hero).where(Hero.id == id)
|
|
return session.exec(statement).first()
|