Exemplo n.º 1
0
    def register_context():
        bad_config = ""
        constructed_context = None
        try:
            if context:
                if isinstance(context, CryptContext):
                    constructed_context = context
                else:
                    msg = "'context' must be an instance of passlib.CryptContext"
                    bad_config = msg
            elif ini_string:
                constructed_context = CryptContext.from_string(ini_string)
            elif ini_file:
                constructed_context = CryptContext.from_path(ini_file)
            elif context_dict:
                constructed_context = CryptContext(**context_dict)
            else:
                # no required arguments have been passed, error
                bad_config = 'requires a CryptContext or configuration data'
        except IOError:
            bad_config = "unable to open %s" % ini_file
        except ValueError:
            bad_config = "received invalid or incompatible configuration options"
        except KeyError:
            bad_config = "received unknown or forbidden configuration options"
        except TypeError:
            bad_config = "received configuration options of the wrong type"

        if bad_config:
            raise ConfigurationError("set_password_context %s" % bad_config)

        config.registry.password_context = constructed_context
Exemplo n.º 2
0
def test_context_update():
    """test speed of CryptContext.update()"""
    kwds = dict(
        schemes=[
            "sha512_crypt", "sha256_crypt", "md5_crypt", "des_crypt",
            "unix_disabled"
        ],
        deprecated=["des_crypt"],
        sha512_crypt__min_rounds=4000,
    )
    ctx = CryptContext.from_path(sample_config_1p)

    def helper():
        ctx.copy(**kwds)

    return helper
Exemplo n.º 3
0
def test_context_update():
    """test speed of CryptContext.update()"""
    kwds = dict(
        schemes = [ "sha512_crypt", "sha256_crypt", "md5_crypt",
                    "des_crypt", "unix_disabled" ],
        deprecated = [ "des_crypt" ],
        sha512_crypt__min_rounds=4000,
        )
    if CryptPolicy:
        policy=CryptPolicy.from_path(sample_config_1p)
        def helper():
            policy.replace(**kwds)
    else:
        ctx = CryptContext.from_path(sample_config_1p)
        def helper():
            ctx.copy(**kwds)
    return helper
Exemplo n.º 4
0
Arquivo: config.py Projeto: csdms/wmt
def _read_config_file(path_to_file, prefix=None):
    from ConfigParser import ConfigParser
    from passlib.context import CryptContext

    config = ConfigParser()
    config.read(path_to_file)

    if prefix is None:
        prefix = os.path.abspath(
            os.path.join(os.path.dirname(path_to_file), '..'))

    site = dict(config.items('paths'))
    for (name, path) in site.items():
        site[name] = os.path.join(prefix, path)
    site.update(config.items('url'))
    for (key, value) in config.items('pickup'):
        site['pickup_' + key] = value

    site['pw'] = CryptContext.from_path(path_to_file, section='passlib')
    return site
Exemplo n.º 5
0
    'LoginAttempt',
    'UserAction',
    'UserGroup',
    'Warning_',
    'UserApplication',
    'EmailResetPassword',
    'UserConfigStart',
    'UserConfig',
]
logger = logging.getLogger(__name__)
_has_password = '******' in re.split(
    '[,+]', config.get('session', 'authentications', default='password'))

passlib_path = config.get('password', 'passlib')
if passlib_path:
    CRYPT_CONTEXT = CryptContext.from_path(passlib_path)
else:
    schemes = ['pbkdf2_sha512']
    if bcrypt:
        schemes.insert(0, 'bcrypt')
    CRYPT_CONTEXT = CryptContext(schemes=schemes)


def gen_password(length=8):
    alphabet = string.ascii_letters + string.digits
    if secrets:
        choice = secrets.choice
    else:
        sysrand = random.SystemRandom()
        choice = sysrand.choice
    return ''.join(choice(alphabet) for _ in range(length))
Exemplo n.º 6
0
 def helper():
     CryptContext.from_path(path)
Exemplo n.º 7
0
 def test_custom_context(self):
     ctx = CryptContext.from_path(INI_FILE_PATH)
     self.config.set_password_context(context=ctx)
     self.assertTrue(self.config.registry.password_context is ctx)
Exemplo n.º 8
0
 def helper():
     CryptContext.from_path(path)
Exemplo n.º 9
0
 def test_custom_context(self):
     ctx = CryptContext.from_path(INI_FILE_PATH)
     self.config.set_password_context(context=ctx)
     self.assertTrue(self.config.registry.password_context is ctx)