示例#1
0
    def __init__(self, config):
        """Create a password context for hashing and verification.

        :param config: The `IConfiguration` instance.
        """
        config_string = load_external(config.passwords.configuration)
        self._context = CryptContext.from_string(config_string)
示例#2
0
    def __init__(self, config):
        """Create a password context for hashing and verification.

        :param config: The `IConfiguration` instance.
        """
        config_string = load_external(config.passwords.configuration)
        self._context = CryptContext.from_string(config_string)
示例#3
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
示例#4
0
 def __init__(self, config):
     # Is the context coming from a file system or Python path?
     if config.passwords.path.startswith('python:'):
         resource_path = config.passwords.path[7:]
         package, dot, resource = resource_path.rpartition('.')
         config_string = resource_string(package, resource + '.cfg')
     else:
         with open(config.passwords.path, 'rb') as fp:
             config_string = fp.read()
     self._context = CryptContext.from_string(config_string)
示例#5
0
    def test_13_config_defaults(self):
        """test PASSLIB_CONFIG default behavior"""
        # check implicit default
        from passlib.ext.django.utils import PASSLIB_DEFAULT
        default = CryptContext.from_string(PASSLIB_DEFAULT)
        self.load_extension()
        self.assert_patched(PASSLIB_DEFAULT)

        # check default preset
        self.load_extension(PASSLIB_CONTEXT="passlib-default", check=False)
        self.assert_patched(PASSLIB_DEFAULT)

        # check explicit string
        self.load_extension(PASSLIB_CONTEXT=PASSLIB_DEFAULT, check=False)
        self.assert_patched(PASSLIB_DEFAULT)
示例#6
0
    def test_13_config_defaults(self):
        """test PASSLIB_CONFIG default behavior"""
        # check implicit default
        from passlib.ext.django.utils import PASSLIB_DEFAULT
        default = CryptContext.from_string(PASSLIB_DEFAULT)
        self.load_extension()
        self.assert_patched(PASSLIB_DEFAULT)

        # check default preset
        self.load_extension(PASSLIB_CONTEXT="passlib-default", check=False)
        self.assert_patched(PASSLIB_DEFAULT)

        # check explicit string
        self.load_extension(PASSLIB_CONTEXT=PASSLIB_DEFAULT, check=False)
        self.assert_patched(PASSLIB_DEFAULT)
示例#7
0
from passlib.context import CryptContext

hashes = ["pbkdf2_sha256", "md5_crypt", "des_crypt"]
deprecated = ["md5_crypt", "des_crypt"]
ctx = CryptContext(schemes=hashes, deprecated=deprecated)

serialized = ctx.to_string()
new_ctx = CryptContext.from_string(serialized)

res = ctx.hash("good password")
print(ctx.verify_and_update("good password", res))