def crypt_ctx(self): ctx = stack.top if ctx is not None: if not hasattr(self, '_crypt_ctx'): self._crypt_ctx = LazyCryptContext( **current_app.config['PASSLIB_CONTEXT']) return self._crypt_ctx
def __init__(self, max_length=None, **kwargs): # Fail if passlib is not found. if passlib is None: raise ImproperlyConfigured( "'passlib' is required to use 'PasswordType'") # Construct the passlib crypt context. self.context = LazyCryptContext(**kwargs) self._max_length = max_length
def test_kwd_constructor(self): self.assertFalse(has_crypt_handler("dummy_2")) register_crypt_handler_path("dummy_2", "passlib.tests.test_context") cc = LazyCryptContext(iter(["dummy_2", "des_crypt"]), deprecated=["des_crypt"]) self.assertFalse(has_crypt_handler("dummy_2", True)) self.assertTrue(cc.policy.handler_is_deprecated("des_crypt")) self.assertEqual(cc.policy.schemes(), ["dummy_2", "des_crypt"]) self.assertTrue(has_crypt_handler("dummy_2", True))
def test_callable_constructor(self): self.assertFalse(has_crypt_handler("dummy_2")) register_crypt_handler_path("dummy_2", "passlib.tests.test_context") def create_policy(flag=False): self.assertTrue(flag) return CryptPolicy(schemes=iter(["dummy_2", "des_crypt"]), deprecated=["des_crypt"]) cc = LazyCryptContext(create_policy=create_policy, flag=True) self.assertFalse(has_crypt_handler("dummy_2", True)) self.assertTrue(cc.policy.handler_is_deprecated("des_crypt")) self.assertEqual(cc.policy.schemes(), ["dummy_2", "des_crypt"]) self.assertTrue(has_crypt_handler("dummy_2", True))
def __init__(self, **kwargs): super().__init__() self.context = LazyCryptContext(**kwargs)
"openbsd_context", "netbsd_context", "freebsd_context", "host_context", ] # ============================================================================= # linux support # ============================================================================= # known platform names - linux2 linux_context = linux2_context = LazyCryptContext( schemes=[ "sha512_crypt", "sha256_crypt", "md5_crypt", "des_crypt", "unix_disabled" ], deprecated=["des_crypt"], ) # ============================================================================= # bsd support # ============================================================================= # known platform names - # freebsd2 # freebsd3 # freebsd4 # freebsd5 # freebsd6 # freebsd7
# 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", all__vary_rounds = 0.1, # set a good starting point for rounds selection sha512_crypt__min_rounds = 60000, sha256_crypt__min_rounds = 80000,
from passlib.context import LazyCryptContext olea_context = LazyCryptContext(schemes=['argon2'], argon2__time_cost=2, argon2__memory_cost=256 * 1024, argon2__parallelism=4)
from distutils.version import StrictVersion from passlib.context import LazyCryptContext import werkzeug from .handlers import (werkzeug_salted_md5, werkzeug_salted_sha1, werkzeug_salted_sha224, werkzeug_salted_sha256, werkzeug_salted_sha384, werkzeug_salted_sha512) werkzeug061_context = LazyCryptContext( schemes=[ werkzeug_salted_md5, werkzeug_salted_sha1, ], default='werkzeug_salted_sha1', ) werkzeugdev_context = LazyCryptContext( schemes=[ werkzeug_salted_md5, werkzeug_salted_sha1, werkzeug_salted_sha224, werkzeug_salted_sha256, werkzeug_salted_sha384, werkzeug_salted_sha512, ], default='werkzeug_salted_sha1', ) if StrictVersion('0.6.1') <= StrictVersion(werkzeug.__version__) <= StrictVersion('0.8.3'):
def __init__(self, max_length=None, **kwargs): self._max_length = max_length self.context = LazyCryptContext(**kwargs) super(PasswordType, self).__init__()
from passlib.context import LazyCryptContext from {{ cookiecutter.repo_name }}.models.types.password import Password context = LazyCryptContext(schemes=[ 'md5_crypt' ]) def test_password(): pwd = Password(context.hash("test_password"), context) assert pwd == "test_password", "Comparing against plaintext should work" assert pwd != "wrong_password", "not equals should work"