2019-07-13 11:39:06 +02:00
|
|
|
# -*- encoding: utf-8 -*-
|
2020-11-11 22:25:02 +01:00
|
|
|
from bonsai.ldapvaluelist import LDAPValueList
|
2019-07-13 11:39:06 +02:00
|
|
|
from passlib.hash import (
|
|
|
|
ldap_sha1,
|
|
|
|
ldap_bcrypt,
|
|
|
|
ldap_sha256_crypt,
|
|
|
|
ldap_sha512_crypt,
|
|
|
|
ldap_pbkdf2_sha256,
|
|
|
|
ldap_pbkdf2_sha512,
|
|
|
|
)
|
|
|
|
|
|
|
|
HASH_CALLABLE = {
|
|
|
|
"sha1": ldap_sha1.hash,
|
|
|
|
"bcrypt": ldap_bcrypt.hash,
|
|
|
|
"sha256_crypt": ldap_sha256_crypt.hash,
|
|
|
|
"sha512_crypt": ldap_sha512_crypt.hash,
|
|
|
|
"pbkdf2_sha256": ldap_pbkdf2_sha256.hash,
|
|
|
|
"pbkdf2_sha512": ldap_pbkdf2_sha512.hash,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def hash_pass(password, method="sha1"):
|
|
|
|
return HASH_CALLABLE[method](password)
|
2020-11-11 22:25:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
def handle_password(password, method="sha1"):
|
|
|
|
if isinstance(password, LDAPValueList):
|
|
|
|
return password
|
|
|
|
return hash_pass(password, method)
|