mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Make bcrypt + passlib work in password_hash filter
If hashtype for the password_hash filter is 'blowfish' and passlib is available, hashing fails as the hash function for this is named 'bcrypt' (and not 'blowfish_crypt'). Special case this so that the correct function is called.
This commit is contained in:
parent
843de98bad
commit
692bfa872a
1 changed files with 5 additions and 1 deletions
|
@ -256,8 +256,12 @@ def get_encrypted_password(password, hashtype='sha512', salt=None):
|
||||||
raise errors.AnsibleFilterError('|password_hash requires the passlib python module to generate password hashes on Mac OS X/Darwin')
|
raise errors.AnsibleFilterError('|password_hash requires the passlib python module to generate password hashes on Mac OS X/Darwin')
|
||||||
saltstring = "$%s$%s" % (cryptmethod[hashtype],salt)
|
saltstring = "$%s$%s" % (cryptmethod[hashtype],salt)
|
||||||
encrypted = crypt.crypt(password, saltstring)
|
encrypted = crypt.crypt(password, saltstring)
|
||||||
|
else:
|
||||||
|
if hashtype == 'blowfish':
|
||||||
|
cls = passlib.hash.bcrypt;
|
||||||
else:
|
else:
|
||||||
cls = getattr(passlib.hash, '%s_crypt' % hashtype)
|
cls = getattr(passlib.hash, '%s_crypt' % hashtype)
|
||||||
|
|
||||||
encrypted = cls.encrypt(password, salt=salt)
|
encrypted = cls.encrypt(password, salt=salt)
|
||||||
|
|
||||||
return encrypted
|
return encrypted
|
||||||
|
|
Loading…
Reference in a new issue