No Description
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.

password_hash.py 1014B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from ansible.errors import AnsibleError, AnsibleUndefinedVariable
  2. from jinja2 import StrictUndefined
  3. __metaclass__ = type
  4. try:
  5. import passlib.hash
  6. HAS_LIB = True
  7. except ImportError:
  8. HAS_LIB = False
  9. def check_lib():
  10. if not HAS_LIB:
  11. raise AnsibleError('You need to install "passlib" prior to running '
  12. 'password_hash-based filters')
  13. def doveadm_pw_hash(password):
  14. check_lib()
  15. if type(password) is StrictUndefined:
  16. raise AnsibleUndefinedVariable('Please pass a string into this password_hash-based filter')
  17. return passlib.hash.sha512_crypt.encrypt(password, rounds=5000)
  18. def znc_pw_salt(password):
  19. return doveadm_pw_hash(password).split("$")[0]
  20. def znc_pw_hash(password):
  21. return doveadm_pw_hash(password).split("$")[1]
  22. class FilterModule(object):
  23. def filters(self):
  24. return {
  25. 'doveadm_pw_hash': doveadm_pw_hash,
  26. 'znc_pw_salt': znc_pw_salt,
  27. 'znc_pw_hash': znc_pw_hash,
  28. }