module documentation

Django's standard crypto functions and utilities.
Constant RANDOM​_STRING​_CHARS Undocumented
Class ​Invalid​Algorithm Algorithm is not supported by hashlib.
Function constant​_time​_compare Return True if the two strings are equal, False otherwise.
Function get​_random​_string Return a securely generated random string.
Function pbkdf2 Return the hash of password using pbkdf2.
Function salted​_hmac Return the HMAC of 'value', using a key generated from key_salt and a secret (which defaults to settings.SECRET_KEY). Default algorithm is SHA1, but any algorithm name supported by hashlib can be passed.
RANDOM_STRING_CHARS: str =

Undocumented

Value
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
def constant_time_compare(val1, val2):
Return True if the two strings are equal, False otherwise.
def get_random_string(length, allowed_chars=RANDOM_STRING_CHARS):

Return a securely generated random string.

The bit length of the returned value can be calculated with the formula:
log_2(len(allowed_chars)^length)
For example, with default allowed_chars (26+26+10), this gives:
  • length: 12, bit length =~ 71 bits
  • length: 22, bit length =~ 131 bits
def pbkdf2(password, salt, iterations, dklen=0, digest=None):
Return the hash of password using pbkdf2.
def salted_hmac(key_salt, value, secret=None, *, algorithm='sha1'):

Return the HMAC of 'value', using a key generated from key_salt and a secret (which defaults to settings.SECRET_KEY). Default algorithm is SHA1, but any algorithm name supported by hashlib can be passed.

A different key_salt should be passed in for every application of HMAC.