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


Python pbkdf2_sha256.hash方法代码示例

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


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

示例1: test_verify_password_single_hash_list

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [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: create

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def create(self):
        """Create the user table."""
        self.cursor.execute('''CREATE TABLE "user" (
            id SERIAL PRIMARY KEY,
            username TEXT NOT NULL,
            password TEXT DEFAULT NULL,
            fs_uid INT NOT NULL,
            email TEXT,
            priority SMALLINT NOT NULL DEFAULT 0,
            enabled BOOLEAN NOT NULL DEFAULT TRUE,
            auth_source TEXT NOT NULL,
            role_id INT REFERENCES role,
            quota_id INT REFERENCES quota
        )''')
        self.cursor.execute('CREATE UNIQUE INDEX users_username_uindex ON "user" (username)')
        hashed_default_pw = hash_algo.hash('admin')
        query = self.cursor.mogrify('INSERT INTO "user" (id, username, password, fs_uid, email, priority, enabled, auth_source, role_id, quota_id) VALUES (DEFAULT, %s, %s, 999, NULL, DEFAULT, DEFAULT, %s, 1, 1)', ('admin', hashed_default_pw, 'internal'))
        self.cursor.execute(query)
        self.sql_manager.commit() 
开发者ID:DistributedSystemsGroup,项目名称:zoe,代码行数:21,代码来源:user.py

示例3: test_verify_password_backward_compatibility

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [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

示例4: test_verify_password_argon2

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [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

示例5: CreateUser

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def CreateUser(username, password, name, email):
    try:
        passhash = pbkdf2_sha256.hash(password)
        user = LoginUser(username=username, password=passhash, name=name, email=email, createdon=datetime.utcnow(), modifiedon=datetime.utcnow())
        session.add(user)
        session.commit()
    except:
        session.rollback()
        raise 
开发者ID:tech-quantum,项目名称:sia-cog,代码行数:11,代码来源:projectmgr.py

示例6: UpdateUserPassword

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def UpdateUserPassword(username, password):
    try:
        user = GetUserInfo(username)
        if user is None:
            raise Exception("User not found")
        user.password = pbkdf2_sha256.hash(password)
        session.commit()
    except:
        session.rollback()
        raise 
开发者ID:tech-quantum,项目名称:sia-cog,代码行数:12,代码来源:projectmgr.py

示例7: set_password

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def set_password(self, password):
		self.password = pbkdf2_sha256.hash(password) 
开发者ID:tspivey,项目名称:yugioh-game,代码行数:4,代码来源:models.py

示例8: set_password

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def set_password(self, new_password: str):
        """Update the password."""
        hashed_password = hash_algo.hash(new_password)
        self.password = hashed_password
        self.sql_manager.user.update(self.id, password=hashed_password) 
开发者ID:DistributedSystemsGroup,项目名称:zoe,代码行数:7,代码来源:user.py

示例9: update

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def update(self, user_id, **fields):
        """Update a user record."""
        if 'password' in fields and fields['password'] is not None:
            fields['password'] = hash_algo.hash(fields['password'])
        super().update(user_id, **fields) 
开发者ID:DistributedSystemsGroup,项目名称:zoe,代码行数:7,代码来源:user.py

示例10: create

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def create(username, displayname, password, email):
        password_hash = pbkdf2_sha256.hash(password)
        user = User(_username=username,
                    _displayname=displayname,
                    _password_hash=password_hash,
                    _email=email)
        db.session.add(user)
        db.session.commit() 
开发者ID:CryptoExperts,项目名称:wb_contest_submission_server,代码行数:10,代码来源:user.py

示例11: create_hash

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def create_hash(string):
    # https://passlib.readthedocs.io/en/stable/narr/hash-tutorial.html
    return pbkdf2_sha256.hash(string) 
开发者ID:geopython,项目名称:GeoHealthCheck,代码行数:5,代码来源:util.py

示例12: verify_hash

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def verify_hash(hash1, hash2):
    # https://passlib.readthedocs.io/en/stable/narr/hash-tutorial.html
    return pbkdf2_sha256.verify(hash1, hash2) 
开发者ID:geopython,项目名称:GeoHealthCheck,代码行数:5,代码来源:util.py

示例13: password

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def password(self, raw: str):
        result = safe.check(raw, length=self.min_password_length, freq=0, min_types=1, level=PASS_COMPLEXITY.TERRIBLE)
        assert result, 'Incorrect password, reason: {}'.format(result.message)
        self._hashed_password = sha256.hash(raw) 
开发者ID:roscisz,项目名称:TensorHive,代码行数:6,代码来源:User.py

示例14: verify_hash

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def verify_hash(password, hash):
        return sha256.verify(password, hash) 
开发者ID:roscisz,项目名称:TensorHive,代码行数:4,代码来源:User.py

示例15: generate_hash

# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import hash [as 别名]
def generate_hash(password):
        return sha256.hash(password) 
开发者ID:oleg-agapov,项目名称:flask-jwt-auth,代码行数:4,代码来源:models.py


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