24 lines
559 B
Python
24 lines
559 B
Python
"""Password helpers.
|
|
|
|
Phase 3B of AUDIT-2026-Q3.md.
|
|
|
|
Public API:
|
|
- hash_password, verify_password
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import bcrypt
|
|
|
|
|
|
def hash_password(password: str) -> str:
|
|
"""Hash password using bcrypt directly."""
|
|
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")
|
|
|
|
|
|
def verify_password(password: str, hashed: str) -> bool:
|
|
"""Verify password against hash."""
|
|
try:
|
|
return bcrypt.checkpw(password.encode("utf-8"), hashed.encode("utf-8"))
|
|
except Exception:
|
|
return False
|