0.6 #ˆl–ßi~”jj"T%õÆY¸Ð”ţà ƒx;¿Æƒ"""passlib.apps""" #============================================================================= # imports #============================================================================= # core import logging; log = logging.getLogger(__name__) from itertools import chain # site # pkg from passlib import hash from passlib.context import LazyCryptContext from passlib.utils import sys_bits # local __all__ = [ 'custom_app_context', 'django_context', 'ldap_context', 'ldap_nocrypt_context', 'mysql_context', 'mysql4_context', 'mysql3_context', 'phpass_context', 'phpbb3_context', 'postgres_context', ] #============================================================================= # master containing all identifiable hashes #============================================================================= def _load_master_config(): from passlib.registry import list_crypt_handlers # get master list schemes = list_crypt_handlers() # exclude the ones we know have ambiguous or greedy identify() methods. excluded = [ # frequently confused for eachother 'bigcrypt', 'crypt16', # no good identifiers 'cisco_pix', 'cisco_type7', 'htdigest', 'mysql323', 'oracle10', # all have same size 'lmhash', 'msdcc', 'msdcc2', 'nthash', # plaintext handlers 'plaintext', 'ldap_plaintext', # disabled handlers 'django_disabled', 'unix_disabled', 'unix_fallback', ] for name in excluded: schemes.remove(name) # return config return dict(schemes=schemes, default="sha256_crypt") master_context = LazyCryptContext(onload=_load_master_config) #============================================================================= # for quickly bootstrapping new custom applications #============================================================================= custom_app_context = LazyCryptContext( # choose some reasonbly strong schemes schemes=["sha512_crypt", "sha256_crypt"], # set some useful global options default="sha256_crypt" if sys_bits < 64 else "sha512_crypt", # set a good starting point for rounds selection sha512_crypt__min_rounds = 535000, sha256_crypt__min_rounds = 535000, # if the admin user category is selected, make a much stronger hash, admin__sha512_crypt__min_rounds = 1024000, admin__sha256_crypt__min_rounds = 1024000, ) #============================================================================= # django #============================================================================= #----------------------------------------------------------------------- # 1.0 #----------------------------------------------------------------------- _django10_schemes = [ "django_salted_sha1", "django_salted_md5", "django_des_crypt", "hex_md5", "django_disabled", ] django10_context = LazyCryptContext( schemes=_django10_schemes, default="django_salted_sha1", deprecated=["hex_md5"], ) #----------------------------------------------------------------------- # 1.4 #----------------------------------------------------------------------- _django14_schemes = [ "django_pbkdf2_sha256", "django_pbkdf2_sha1", "django_bcrypt" ] + _django10_schemes django14_context = LazyCryptContext( schemes=_django14_schemes, deprecated=_django10_schemes, ) #----------------------------------------------------------------------- # 1.6 #----------------------------------------------------------------------- _django16_schemes = list(_django14_schemes) _django16_schemes.insert(1, "django_bcrypt_sha256") django16_context = LazyCryptContext( schemes=_django16_schemes, deprecated=_django10_schemes, ) #----------------------------------------------------------------------- # 1.10 #----------------------------------------------------------------------- _django_110_schemes = [ "django_pbkdf2_sh