예제 #1
0
def _make_cryptcontext():
    try:
        from passlib.context import CryptContext
    except ImportError:
        log.warning(
            "Hashed passwords are disabled because passlib is not installed. Please install "
            "it (pip3 install passlib) and rehash for this feature to work.")
        return

    context_settings = conf.conf.get(
        'login',
        {}).get('cryptcontext_settings') or _DEFAULT_CRYPTCONTEXT_SETTINGS
    global pwd_context
    if pwd_context is None:
        log.debug("Initialized new CryptContext with settings: %s",
                  context_settings)
        pwd_context = CryptContext(**context_settings)
    else:
        log.debug("Updated CryptContext with settings: %s", context_settings)
        pwd_context.update(**context_settings)