dt / app /utils /auth_tools.py
gitdeem's picture
Upload 96 files
4e9efe9 verified
raw
history blame
740 Bytes
#========== utils/auth_tools.py ==========
import random
from datetime import datetime, timedelta
from werkzeug.security import generate_password_hash, check_password_hash
def generate_code(length=6):
"""η”Ÿζˆζ•°ε­—ιͺŒθ―η """
return ''.join(random.choices('0123456789', k=length))
def validate_code(code_record):
"""ιͺŒθ―η ζœ‰ζ•ˆζ€§ζ£€ζŸ₯"""
if not code_record:
return False
return (datetime.utcnow() - code_record.created_at) < timedelta(seconds=1800)
def hash_password(password):
"""ε―†η ε“ˆεΈŒε€„η†"""
return generate_password_hash(password)
def check_password(hashed_password, password):
"""密码树ιͺŒ"""
return check_password_hash(hashed_password, password)