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.
|
|
|
from passlib.context import CryptContext
|
|
|
|
|
|
|
|
pwd_context = CryptContext(schemes=['bcrypt'], deprecated='auto')
|
|
|
|
|
|
|
|
|
|
|
|
class PwdUtil:
|
|
|
|
"""
|
|
|
|
密码工具类
|
|
|
|
"""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def verify_password(cls, plain_password, hashed_password):
|
|
|
|
"""
|
|
|
|
工具方法:校验当前输入的密码与数据库存储的密码是否一致
|
|
|
|
|
|
|
|
:param plain_password: 当前输入的密码
|
|
|
|
:param hashed_password: 数据库存储的密码
|
|
|
|
:return: 校验结果
|
|
|
|
"""
|
|
|
|
return pwd_context.verify(plain_password, hashed_password)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_password_hash(cls, input_password):
|
|
|
|
"""
|
|
|
|
工具方法:对当前输入的密码进行加密
|
|
|
|
|
|
|
|
:param input_password: 输入的密码
|
|
|
|
:return: 加密成功的密码
|
|
|
|
"""
|
|
|
|
return pwd_context.hash(input_password)
|