import bcrypt def hash_password(password: str) -> str: # bcrypt akzeptiert max. 72 Bytes. pw = password.encode("utf-8")[:72] return bcrypt.hashpw(pw, bcrypt.gensalt()).decode("utf-8") def verify_password(password: str, password_hash: str) -> bool: try: pw = password.encode("utf-8")[:72] return bcrypt.checkpw(pw, password_hash.encode("utf-8")) except (ValueError, TypeError): return False