当前位置: 首页>>代码示例>>Python>>正文


Python CryptPolicy.from_string方法代码示例

本文整理汇总了Python中passlib.context.CryptPolicy.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python CryptPolicy.from_string方法的具体用法?Python CryptPolicy.from_string怎么用?Python CryptPolicy.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在passlib.context.CryptPolicy的用法示例。


在下文中一共展示了CryptPolicy.from_string方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_13_get_options

# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_string [as 别名]
    def test_13_get_options(self):
        "test get_options() method"

        p12 = CryptPolicy(**self.sample_config_12pd)

        self.assertEqual(p12.get_options("bsdi_crypt"),dict(
            vary_rounds = "10%",
            min_rounds = 29000,
            max_rounds = 35000,
            default_rounds = 31000,
        ))

        self.assertEqual(p12.get_options("sha512_crypt"),dict(
            vary_rounds = "10%",
            min_rounds = 45000,
            max_rounds = 50000,
        ))

        p4 = CryptPolicy.from_string(self.sample_config_4s)
        self.assertEqual(p4.get_options("sha512_crypt"), dict(
            vary_rounds="10%",
            max_rounds=20000,
        ))

        self.assertEqual(p4.get_options("sha512_crypt", "user"), dict(
            vary_rounds="10%",
            max_rounds=20000,
        ))

        self.assertEqual(p4.get_options("sha512_crypt", "admin"), dict(
            vary_rounds="5%",
            max_rounds=40000,
        ))
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:35,代码来源:test_context.py

示例2: test_22_to_string

# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_string [as 别名]
    def test_22_to_string(self):
        "test to_string() method"
        pa = CryptPolicy(**self.sample_config_5pd)
        s = pa.to_string() #NOTE: can't compare string directly, ordering etc may not match
        pb = CryptPolicy.from_string(s)
        self.assertEqual(pb.to_dict(), self.sample_config_5pd)

        s = pa.to_string(encoding="latin-1")
        self.assertIsInstance(s, bytes)
开发者ID:bbBradenbb,项目名称:gae-starter-kit,代码行数:11,代码来源:test_context_deprecated.py

示例3: test_02_from_string

# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_string [as 别名]
    def test_02_from_string(self):
        "test CryptPolicy.from_string() constructor"
        #test "\n" linesep
        policy = CryptPolicy.from_string(self.sample_config_1s)
        self.assertEqual(policy.to_dict(), self.sample_config_1pd)

        #test "\r\n" linesep
        policy = CryptPolicy.from_string(
            self.sample_config_1s.replace("\n","\r\n"))
        self.assertEqual(policy.to_dict(), self.sample_config_1pd)

        #test with unicode
        data = to_unicode(self.sample_config_1s)
        policy = CryptPolicy.from_string(data)
        self.assertEqual(policy.to_dict(), self.sample_config_1pd)

        #test with non-ascii-compatible encoding
        uc2 = to_bytes(self.sample_config_1s, "utf-16", source_encoding="utf-8")
        policy = CryptPolicy.from_string(uc2, encoding="utf-16")
        self.assertEqual(policy.to_dict(), self.sample_config_1pd)

        #test category specific options
        policy = CryptPolicy.from_string(self.sample_config_4s)
        self.assertEqual(policy.to_dict(), self.sample_config_4pd)
开发者ID:bbBradenbb,项目名称:gae-starter-kit,代码行数:26,代码来源:test_context_deprecated.py

示例4: patch

# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_string [as 别名]
def patch():
    #get config
    ctx = getattr(settings, "PASSLIB_CONTEXT", "passlib-default")
    catfunc = getattr(settings, "PASSLIB_GET_CATEGORY", get_category)

    #parse & validate input value
    if not ctx:
        # remove any patching that was already set, just in case.
        set_django_password_context(None)
        return
    if ctx == "passlib-default":
        ctx = DEFAULT_CTX
    if isinstance(ctx, (unicode, bytes)):
        ctx = CryptPolicy.from_string(ctx)
    if isinstance(ctx, CryptPolicy):
        ctx = CryptContext(policy=ctx)
    if not is_crypt_context(ctx):
        raise TypeError("django settings.PASSLIB_CONTEXT must be CryptContext instance or config string: %r" % (ctx,))

    #monkeypatch django.contrib.auth.models:User
    set_django_password_context(ctx, get_category=catfunc)
开发者ID:ashmashrest,项目名称:python-passlib-buildpackage,代码行数:23,代码来源:models.py

示例5: test_13_get_options

# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_string [as 别名]
    def test_13_get_options(self):
        "test get_options() method"

        p12 = CryptPolicy(**self.sample_config_12pd)

        self.assertEqual(p12.get_options("bsdi_crypt"),dict(
            # NOTE: not maintaining backwards compat for rendering to "10%"
            vary_rounds = 0.1,
            min_rounds = 29000,
            max_rounds = 35000,
            default_rounds = 31000,
        ))

        self.assertEqual(p12.get_options("sha512_crypt"),dict(
            # NOTE: not maintaining backwards compat for rendering to "10%"
            vary_rounds = 0.1,
            min_rounds = 45000,
            max_rounds = 50000,
        ))

        p4 = CryptPolicy.from_string(self.sample_config_4s)
        self.assertEqual(p4.get_options("sha512_crypt"), dict(
            # NOTE: not maintaining backwards compat for rendering to "10%"
            vary_rounds=0.1,
            max_rounds=20000,
        ))

        self.assertEqual(p4.get_options("sha512_crypt", "user"), dict(
            # NOTE: not maintaining backwards compat for rendering to "10%"
            vary_rounds=0.1,
            max_rounds=20000,
        ))

        self.assertEqual(p4.get_options("sha512_crypt", "admin"), dict(
            # NOTE: not maintaining backwards compat for rendering to "5%"
            vary_rounds=0.05,
            max_rounds=40000,
        ))
开发者ID:bbBradenbb,项目名称:gae-starter-kit,代码行数:40,代码来源:test_context_deprecated.py


注:本文中的passlib.context.CryptPolicy.from_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。