MCPcopy
hub / github.com/django/django / identify_hasher

Function identify_hasher

django/contrib/auth/hashers.py:173–192  ·  view source on GitHub ↗

Return an instance of a loaded password hasher. Identify hasher algorithm by examining encoded hash, and call get_hasher() to return hasher. Raise ValueError if algorithm cannot be identified, or if hasher is not loaded.

(encoded)

Source from the content-addressed store, hash-verified

171
172
173def identify_hasher(encoded):
174 """
175 Return an instance of a loaded password hasher.
176
177 Identify hasher algorithm by examining encoded hash, and call
178 get_hasher() to return hasher. Raise ValueError if
179 algorithm cannot be identified, or if hasher is not loaded.
180 """
181 # Ancient versions of Django created plain MD5 passwords and accepted
182 # MD5 passwords with an empty salt.
183 if (len(encoded) == 32 and "$" not in encoded) or (
184 len(encoded) == 37 and encoded.startswith("md5$$")
185 ):
186 algorithm = "unsalted_md5"
187 # Ancient versions of Django accepted SHA1 passwords with an empty salt.
188 elif len(encoded) == 46 and encoded.startswith("sha1$$"):
189 algorithm = "unsalted_sha1"
190 else:
191 algorithm = encoded.split("$", 1)[0]
192 return get_hasher(algorithm)
193
194
195def mask_hash(hash, show=6, char="*"):

Callers 10

render_password_as_hashFunction · 0.90
test_pbkdf2Method · 0.90
test_md5Method · 0.90
test_bcrypt_sha256Method · 0.90
test_bcryptMethod · 0.90
test_unusableMethod · 0.90
test_bad_algorithmMethod · 0.90
test_argon2Method · 0.90
test_scryptMethod · 0.90
verify_passwordFunction · 0.85

Calls 2

get_hasherFunction · 0.85
splitMethod · 0.45

Tested by 8

test_pbkdf2Method · 0.72
test_md5Method · 0.72
test_bcrypt_sha256Method · 0.72
test_bcryptMethod · 0.72
test_unusableMethod · 0.72
test_bad_algorithmMethod · 0.72
test_argon2Method · 0.72
test_scryptMethod · 0.72