You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
470 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import bcrypt
# 原始密码
def make_pwd(pwd):
# 加密(生成哈希)
hashed_password = bcrypt.hashpw(pwd.encode('utf-8'), bcrypt.gensalt())
# 存入数据库(转为 str
hashed_password_str = hashed_password.decode('utf-8')
return hashed_password_str
def check_pwd(input_pwd, hashed_pwd):
# 验证密码
try:
return bcrypt.checkpw(input_pwd.encode('utf-8'), hashed_pwd.encode('utf-8'))
except:
return False