Files

17 lines
428 B
Python
Raw Permalink Normal View History

"""
认证安全工具 — passlib + bcrypt
"""
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
def hash_password(plain: str) -> str:
"""用 bcrypt 生成密码哈希。"""
return pwd_context.hash(plain)
def verify_password(plain: str, hashed: str) -> bool:
"""验证明文密码与哈希是否匹配。"""
return pwd_context.verify(plain, hashed)