本文整理匯總了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)