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


Python utils.hash_password方法代码示例

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


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

示例1: test_verify_password_single_hash_list

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def test_verify_password_single_hash_list(app, sqlalchemy_datastore):
    init_app_with_options(
        app,
        sqlalchemy_datastore,
        **{
            "SECURITY_PASSWORD_HASH": "bcrypt",
            "SECURITY_PASSWORD_SALT": "salty",
            "SECURITY_PASSWORD_SINGLE_HASH": ["django_pbkdf2_sha256", "plaintext"],
            "SECURITY_PASSWORD_SCHEMES": [
                "bcrypt",
                "pbkdf2_sha256",
                "django_pbkdf2_sha256",
                "plaintext",
            ],
        }
    )
    with app.app_context():
        # double hash
        assert verify_password("pass", hash_password("pass"))
        assert verify_password("pass", pbkdf2_sha256.hash(get_hmac("pass")))
        # single hash
        assert verify_password("pass", django_pbkdf2_sha256.hash("pass"))
        assert verify_password("pass", plaintext.hash("pass")) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:25,代码来源:test_hashing.py

示例2: add_users_to_db

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def add_users_to_db(user_list):
    default_tenant = Tenant.query.get(DEFAULT_TENANT_ID)
    for user in user_list:
        role = user_datastore.find_role(user['role'])
        user_obj = user_datastore.create_user(
            username=user['username'],
            password=hash_password(user['password']),
            roles=[role]
        )

        default_tenant_role = user_datastore.find_role(DEFAULT_TENANT_ROLE)
        user_obj.active = user.get('active', True)
        user_tenant_association = UserTenantAssoc(
            user=user_obj,
            tenant=default_tenant,
            role=default_tenant_role,
        )
        user_obj.tenant_associations.append(user_tenant_association)
    user_datastore.commit() 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:21,代码来源:security_utils.py

示例3: change_password

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def change_password(email, new_password):
    user = User.objects.get(email=email)
    user.update(password=utils.hash_password(new_password)) 
开发者ID:fkie-cad,项目名称:LuckyCAT,代码行数:5,代码来源:Users.py

示例4: test_verify_password_bcrypt_double_hash

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def test_verify_password_bcrypt_double_hash(app, sqlalchemy_datastore):
    init_app_with_options(
        app,
        sqlalchemy_datastore,
        **{
            "SECURITY_PASSWORD_HASH": "bcrypt",
            "SECURITY_PASSWORD_SALT": "salty",
            "SECURITY_PASSWORD_SINGLE_HASH": False,
        }
    )
    with app.app_context():
        assert verify_password("pass", hash_password("pass")) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:14,代码来源:test_hashing.py

示例5: test_verify_password_bcrypt_single_hash

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def test_verify_password_bcrypt_single_hash(app, sqlalchemy_datastore):
    init_app_with_options(
        app,
        sqlalchemy_datastore,
        **{
            "SECURITY_PASSWORD_HASH": "bcrypt",
            "SECURITY_PASSWORD_SALT": None,
            "SECURITY_PASSWORD_SINGLE_HASH": True,
        }
    )
    with app.app_context():
        assert verify_password("pass", hash_password("pass")) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:14,代码来源:test_hashing.py

示例6: test_verify_password_backward_compatibility

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def test_verify_password_backward_compatibility(app, sqlalchemy_datastore):
    init_app_with_options(
        app,
        sqlalchemy_datastore,
        **{
            "SECURITY_PASSWORD_HASH": "bcrypt",
            "SECURITY_PASSWORD_SINGLE_HASH": False,
            "SECURITY_PASSWORD_SCHEMES": ["bcrypt", "plaintext"],
        }
    )
    with app.app_context():
        # double hash
        assert verify_password("pass", hash_password("pass"))
        # single hash
        assert verify_password("pass", plaintext.hash("pass")) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:17,代码来源:test_hashing.py

示例7: test_verify_password_argon2

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def test_verify_password_argon2(app, sqlalchemy_datastore):
    init_app_with_options(
        app, sqlalchemy_datastore, **{"SECURITY_PASSWORD_HASH": "argon2"}
    )
    with app.app_context():
        hashed_pwd = hash_password("pass")
        assert verify_password("pass", hashed_pwd)
        assert "t=10" in hashed_pwd

        # Verify double hash
        assert verify_password("pass", argon2.hash(get_hmac("pass"))) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:13,代码来源:test_hashing.py

示例8: test_bcrypt_speed

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def test_bcrypt_speed(app, sqlalchemy_datastore):
    init_app_with_options(
        app,
        sqlalchemy_datastore,
        **{
            "SECURITY_PASSWORD_HASH": "bcrypt",
            "SECURITY_PASSWORD_SALT": "salty",
            "SECURITY_PASSWORD_SINGLE_HASH": False,
        }
    )
    with app.app_context():
        print(timeit.timeit(lambda: hash_password("pass"), number=100)) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:14,代码来源:test_hashing.py

示例9: test_argon2_speed

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def test_argon2_speed(app, sqlalchemy_datastore):
    init_app_with_options(
        app,
        sqlalchemy_datastore,
        **{
            "SECURITY_PASSWORD_HASH": "argon2",
            "SECURITY_PASSWORD_HASH_PASSLIB_OPTIONS": {"argon2__rounds": 10},
        }
    )
    with app.app_context():
        print(
            "Hash time for {} iterations: {}".format(
                100, timeit.timeit(lambda: hash_password("pass"), number=100)
            )
        ) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:17,代码来源:test_hashing.py

示例10: create_users

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def create_users(app, ds, count=None):
    users = [
        ("matt@lp.com", "matt", "password", ["admin"], True, 123456, None),
        ("joe@lp.com", "joe", "password", ["editor"], True, 234567, None),
        ("dave@lp.com", "dave", "password", ["admin", "editor"], True, 345678, None),
        ("jill@lp.com", "jill", "password", ["author"], True, 456789, None),
        ("tiya@lp.com", "tiya", "password", [], False, 567890, None),
        ("gene@lp.com", "gene", "password", ["simple"], True, 889900, None),
        ("jess@lp.com", "jess", None, [], True, 678901, None),
        ("gal@lp.com", "gal", "password", ["admin"], True, 112233, "sms"),
        ("gal2@lp.com", "gal2", "password", ["admin"], True, 223311, "authenticator"),
        ("gal3@lp.com", "gal3", "password", ["admin"], True, 331122, "mail"),
    ]
    count = count or len(users)

    for u in users[:count]:
        pw = u[2]
        if pw is not None:
            pw = hash_password(pw)
        roles = [ds.find_or_create_role(rn) for rn in u[3]]
        ds.commit()
        totp_secret = None
        if app.config.get("SECURITY_TWO_FACTOR", None) and u[6]:
            totp_secret = app.security._totp_factory.generate_totp_secret()
        user = ds.create_user(
            email=u[0],
            username=u[1],
            password=pw,
            active=u[4],
            security_number=u[5],
            tf_primary_method=u[6],
            tf_totp_secret=totp_secret,
        )
        ds.commit()
        for role in roles:
            ds.add_role_to_user(user, role)
        ds.commit() 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:39,代码来源:test_utils.py

示例11: add_user

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def add_user(ds, email, password, roles):
    pw = hash_password(password)
    roles = [ds.find_or_create_role(rn) for rn in roles]
    ds.commit()
    user = ds.create_user(
        email=email, password=pw, active=True, confirmed_at=datetime.datetime.utcnow()
    )
    ds.commit()
    for role in roles:
        ds.add_role_to_user(user, role)
    ds.commit() 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:13,代码来源:view_scaffold.py

示例12: create_admin_user

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def create_admin_user(user_datastore, app):
    with app.app_context():    
        if user_datastore.get_user("admin"):
            pass
        else:
            user_role = user_datastore.find_role(role='user')
            super_user_role = user_datastore.find_role(role='superuser')
            user_datastore.create_user(name='admin', email='admin', password=hash_password('admin'), roles=[user_role, super_user_role]) 
开发者ID:ozhiwei,项目名称:SmartProxyPool,代码行数:10,代码来源:admin.py

示例13: _adjust_kwargs

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def _adjust_kwargs(cls, **kwargs):
        if 'password' in kwargs:
            # Password is stored hashed
            kwargs['password'] = hash_password(kwargs['password'])
        return kwargs 
开发者ID:opendatateam,项目名称:udata,代码行数:7,代码来源:factories.py

示例14: create_default_user_tenant_and_roles

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def create_default_user_tenant_and_roles(admin_username,
                                         admin_password,
                                         amqp_manager,
                                         authorization_file_path):
    """
    Create the bootstrap admin, the default tenant and the security roles,
    as well as a RabbitMQ vhost and user corresponding to the default tenant

    :return: The default tenant
    """
    admin_role = _create_roles(authorization_file_path)
    default_tenant = _create_default_tenant()
    amqp_manager.create_tenant_vhost_and_user(tenant=default_tenant)

    admin_user = user_datastore.create_user(
        id=constants.BOOTSTRAP_ADMIN_ID,
        username=admin_username,
        password=hash_password(admin_password),
        roles=[admin_role]
    )

    # The admin user is assigned to the default tenant.
    # This is the default role when a user is added to a tenant.
    # Anyway, `sys_admin` will be the effective role since is the system role.
    user_role = user_datastore.find_role(constants.DEFAULT_TENANT_ROLE)
    user_tenant_association = UserTenantAssoc(
        user=admin_user,
        tenant=default_tenant,
        role=user_role,
    )
    admin_user.tenant_associations.append(user_tenant_association)
    user_datastore.commit()
    return default_tenant 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:35,代码来源:storage_utils.py

示例15: create_status_reporter_user_and_assign_role

# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import hash_password [as 别名]
def create_status_reporter_user_and_assign_role(username,
                                                password,
                                                role,
                                                user_id):
    """Creates a user and assigns its given role.
    """
    user = user_datastore.create_user(
        username=username,
        password=hash_password(password),
        roles=[role],
        id=user_id
    )

    default_tenant = Tenant.query.filter_by(
        id=constants.DEFAULT_TENANT_ID).first()
    reporter_role = user_datastore.find_role(role)
    if not reporter_role:
        raise NotFoundError("The username \"{0}\" cannot have the role \"{1}\""
                            " as the role doesn't exist"
                            "".format(username, role))
    user_tenant_association = UserTenantAssoc(
        user=user,
        tenant=default_tenant,
        role=reporter_role,
    )
    user.tenant_associations.append(user_tenant_association)
    user_datastore.commit()
    return user 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:30,代码来源:storage_utils.py


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