本文整理汇总了Python中flask_security.utils.verify_password方法的典型用法代码示例。如果您正苦于以下问题:Python utils.verify_password方法的具体用法?Python utils.verify_password怎么用?Python utils.verify_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_security.utils
的用法示例。
在下文中一共展示了utils.verify_password方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_verify_password_single_hash_list
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_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"))
示例2: _http_auth
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_password [as 别名]
def _http_auth(self, user, username, password):
"""Perform basic user authentication
- Check that the password that was passed in the request can be
verified against the password stored in the DB
:param user: The DB user object
:param username: The username from the request
:param password: The password from the request
:return: The DB user object
"""
self.logger.debug('Running basic HTTP authentication')
if not user:
raise_unauthorized_user_error(
'Authentication failed for '
'<User username=`{0}`>'.format(username)
)
if not verify_password(password, user.password):
self._increment_failed_logins_counter(user)
raise_unauthorized_user_error(
'Authentication failed for {0}.'
' Bad credentials or locked account'.format(user)
)
return user
示例3: correct_password
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_password [as 别名]
def correct_password(email, password):
user = User.objects.get(email=email)
return utils.verify_password(password, user.password)
示例4: post
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_password [as 别名]
def post(self):
args = parser.parse_args()
email = args['email']
password = args['password']
if email is None or password is None:
return {'message': "Email or password empty"}, 401
user = User.query.filter_by(email=args["email"]).first()
if security_utils.verify_password(password, user.password):
return {'message': 'Login Successful', 'apikey': user.api_key}, 200
return {'message': 'Login Failed'}, 401
示例5: test_verify_password_bcrypt_double_hash
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_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"))
示例6: test_verify_password_bcrypt_single_hash
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_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"))
示例7: test_verify_password_backward_compatibility
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_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"))
示例8: test_verify_password_argon2
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_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")))
示例9: authenticate_user
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_password [as 别名]
def authenticate_user(self, username, password):
user = User.objects(email=username).first()
if user and verify_password(password, user.password):
return user
示例10: authenticate
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_password [as 别名]
def authenticate(username, password):
user = user_datastore.find_user(email=username)
if user and username == user.email and verify_password(password, user.password):
return user
return None
示例11: password_is_correct
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import verify_password [as 别名]
def password_is_correct(self, user_name, password):
user = self.find_user(email=user_name)
return verify_password(password, user.password)