pwd_util.py 791 B

123456789101112131415161718192021222324252627282930
  1. from passlib.context import CryptContext
  2. pwd_context = CryptContext(schemes=['bcrypt'], deprecated='auto')
  3. class PwdUtil:
  4. """
  5. 密码工具类
  6. """
  7. @classmethod
  8. def verify_password(cls, plain_password, hashed_password):
  9. """
  10. 工具方法:校验当前输入的密码与数据库存储的密码是否一致
  11. :param plain_password: 当前输入的密码
  12. :param hashed_password: 数据库存储的密码
  13. :return: 校验结果
  14. """
  15. return pwd_context.verify(plain_password, hashed_password)
  16. @classmethod
  17. def get_password_hash(cls, input_password):
  18. """
  19. 工具方法:对当前输入的密码进行加密
  20. :param input_password: 输入的密码
  21. :return: 加密成功的密码
  22. """
  23. return pwd_context.hash(input_password)