possibilité de spécifier le salt
This commit is contained in:
parent
6b746a83bc
commit
b750422b94
|
@ -124,10 +124,10 @@ def gen_binary_hash(pw, scheme, salt=None):
|
||||||
|
|
||||||
return base64.b64encode(hash)
|
return base64.b64encode(hash)
|
||||||
|
|
||||||
def gen_hash(pw, scheme=None, ref=None, normalized=True):
|
def gen_hash(pw, scheme=None, ref=None, salt=None, normalized=True):
|
||||||
if ref is not None:
|
if ref is not None:
|
||||||
scheme = get_scheme(ref)
|
scheme = get_scheme(ref)
|
||||||
salt = get_salt(ref)
|
if salt is None: salt = get_salt(ref)
|
||||||
if is_crypt_scheme(scheme):
|
if is_crypt_scheme(scheme):
|
||||||
hash = gen_crypt_hash(pw, salt)
|
hash = gen_crypt_hash(pw, salt)
|
||||||
else:
|
else:
|
||||||
|
@ -135,12 +135,12 @@ def gen_hash(pw, scheme=None, ref=None, normalized=True):
|
||||||
elif scheme is not None:
|
elif scheme is not None:
|
||||||
scheme = get_scheme(scheme)
|
scheme = get_scheme(scheme)
|
||||||
if is_crypt_scheme(scheme):
|
if is_crypt_scheme(scheme):
|
||||||
hash = gen_crypt_hash(pw)
|
hash = gen_crypt_hash(pw, salt)
|
||||||
else:
|
else:
|
||||||
hash = gen_binary_hash(pw, scheme)
|
hash = gen_binary_hash(pw, scheme, salt)
|
||||||
else:
|
else:
|
||||||
# Par défaut, hasher en crypt
|
# Par défaut, hasher en crypt
|
||||||
scheme = '{CRYPT}'
|
scheme = '{CRYPT}'
|
||||||
hash = gen_crypt_hash(pw)
|
hash = gen_crypt_hash(pw, salt)
|
||||||
if normalized: hash = scheme + hash
|
if normalized: hash = scheme + hash
|
||||||
return hash
|
return hash
|
||||||
|
|
Loading…
Reference in New Issue