本文整理汇总了Python中passlib.hash.pbkdf2_sha256.verify方法的典型用法代码示例。如果您正苦于以下问题:Python pbkdf2_sha256.verify方法的具体用法?Python pbkdf2_sha256.verify怎么用?Python pbkdf2_sha256.verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类passlib.hash.pbkdf2_sha256
的用法示例。
在下文中一共展示了pbkdf2_sha256.verify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_verify_hash
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def test_verify_hash(self):
"""Test verify hash.
Also needs app context to access config.
"""
with self.app.app_context():
hashed = self.app.config['PASSWORD_CONTEXT'].hash("some_pw")
# Correct password
self.assertTrue(
verify_password({'password': hashed}, "some_pw")
)
# Wrong password
self.assertFalse(
verify_password({'password': hashed}, "NotThePassword")
)
示例2: assertRehashed
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def assertRehashed(self, user_id, plaintext, old_hash):
"""Assert that the password was rehased.
Check
- that the password in the database is not the old hash
- that the password in the datbase is a correct hash of the password
Args:
user_id (ObjectId): Id of user
plaintext (str): Password of user as plaintext
old_hash (str): Old hash of passwor
"""
user = self.db['users'].find_one({'_id': user_id})
self.assertNotEqual(user['password'], old_hash)
self.assertTrue(pbkdf2_sha256.verify(plaintext, user['password']))
示例3: verifyUser
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def verifyUser(user, pwd):
person = getUser(user)
return (person and pbkdf2_sha256.verify(pwd, person['password']))
示例4: checkpassword
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def checkpassword(self, pwd):
return pbkdf2_sha256.verify(pwd, self.password)
示例5: verify_password
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def verify_password(password, _hash):
return pbkdf2_sha256.verify(password, _hash)
示例6: ValidateUser
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def ValidateUser(username, password):
result = False
try:
user = GetUserInfo(username)
if user is None:
raise Exception("User not found")
result = pbkdf2_sha256.verify(password, user.password)
except:
raise
return result
示例7: check_password
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def check_password(self, password):
return pbkdf2_sha256.verify(password, self.password)
示例8: check_password
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def check_password(self, candidate_pw: str) -> bool:
"""Checks if the password is correct."""
if self.auth_source != "internal" or self.password is None:
return False
return hash_algo.verify(candidate_pw, self.password)
示例9: test_working_action
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def test_working_action(client):
print('\n> links >{}'.format(User.actions))
user = create_and_save_a_user('test user', 'test password', 'test description')
rsp = client.get('/users/{}'.format(user.id))
print('\nResponse: {} -> {}'.format(rsp.status, rsp.data))
assert rsp.status_code == 200, 'the status code is expected to be 200'
result = rsp.json
assert result.get('_links') is not None
assert 'change_password' in result.get('_links')
assert 'get_description' in result.get('_links')
assert 'self' in result.get('_links')
assert 'collection' in result.get('_links')
change_pass_included = False
newpass = 'new pass'
for link_name, link_value in result.get('_links').items():
if link_name == 'change_password':
change_pass_included = True
post_data = json.dumps({'current_password': 'test password', 'new_password': newpass})
assert link_value.get('href') is not None
rsp = client.post(link_value.get('href'), data=post_data)
print('\nResponse: {} -> {}'.format(rsp.status, rsp.data.decode))
assert rsp.status_code == 200, 'the status code is expected to be 200'
break
assert change_pass_included, 'Should contain change_password link'
rsp = client.get('/users/{}'.format(user.id))
print('\nResponse: {} -> {}'.format(rsp.status, rsp.data.decode()))
assert rsp.status_code == 200, 'the status code is expected to be 200'
result = rsp.json
assert 'password' not in result
assert pbkdf2_sha256.verify(newpass, User.find_by_id(result.get('id')).password)
示例10: change_p
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def change_p(self, current_password, new_password):
if not pbkdf2_sha256.verify(current_password, self.password):
raise ServiceException(403, _('Current password is not correct'))
else:
self.password = new_password
self.save()
return _('Password changed')
示例11: validate
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def validate(username, password):
user = User.query.filter(User._username == username).first()
if user is not None and \
pbkdf2_sha256.verify(password, user._password_hash):
return user
else:
return None
示例12: verify
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def verify(self, password):
return pbkdf2_sha256.verify(password, self._password_hash)
示例13: verify_hash
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def verify_hash(hash1, hash2):
# https://passlib.readthedocs.io/en/stable/narr/hash-tutorial.html
return pbkdf2_sha256.verify(hash1, hash2)
示例14: validate_user
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def validate_user(username,password):
try:
results = db.query("SELECT * FROM users WHERE username=$username ORDER BY ROWID ASC LIMIT 1",
vars={'username': username})
user = results[0]
try:
valid_hash = pbkdf2_sha256.verify(password, user.password)
except ValueError as e:
web.debug('%s user=%s' % (str(e), user.username))
valid_hash = None
pass
date_now = datetime.datetime.now()
date_expires = datetime.datetime.combine(user.expires, datetime.time.min)
if date_now <= date_expires:
if valid_hash:
web.debug('login_success_hash: user=%s' % user.username)
return user
else:
web.debug('login_failed_hash: incorrect password user=%s, fallback to plaintext' % user.username)
if password == user.password:
web.debug('login_success_plaintext: user=%s' % user.username)
return user
else:
web.debug('login_failed_plaintext: incorrect password user=%s' % user.username)
return None
else:
web.debug('login_failed: expired account user=%s' % user.username)
return None
except IndexError as e:
web.debug('login_failed: not found user=%s' % username)
return None
示例15: verify_hash
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import verify [as 别名]
def verify_hash(password, hash):
return sha256.verify(password, hash)