# ========================================================================
# Easy Crypt Library
#

import bcrypt
import secrets
import hashlib



def generate_password_hash(password: str) -> str:
    pw_bytes = password.encode('utf-8')             # Convert to bytes
    salt = bcrypt.gensalt()                         # Generate salt
    pass_hash = bcrypt.hashpw(pw_bytes, salt)       # Hash password
    return pass_hash.decode('utf-8')                # Convert bytes back to string for DB


def check_password_hash(password: str, stored_hash: str) -> bool:
    pw_bytes = password.encode('utf-8')
    hash_bytes = stored_hash.encode('utf-8')
    return bcrypt.checkpw(pw_bytes, hash_bytes)

def generate_session_token() -> str:
    raw = secrets.token_bytes(32)
    return hashlib.sha256(raw).hexdigest()
