本文整理汇总了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"))
示例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()
示例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"))
示例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")))
示例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
示例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
示例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)
示例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)
示例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)
示例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()
示例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)
示例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)
示例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)
示例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)
示例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)