superlishunqin f434b83090 first commit
2025-03-17 22:43:53 +08:00

12 lines
423 B
Python

import bcrypt
def hash_password(password):
"""对密码进行哈希处理"""
# 对密码进行加盐处理并哈希
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(password.encode('utf-8'), salt)
return hashed.decode('utf-8')
def check_password(hashed_password, user_password):
"""验证密码是否匹配"""
return bcrypt.checkpw(user_password.encode('utf-8'), hashed_password.encode('utf-8'))