當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。