Python flask_security.utils.verify_password() Examples

The following are 11 code examples of flask_security.utils.verify_password(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_security.utils , or try the search function .
Example #1
Source File: test_hashing.py    From flask-security with MIT License 6 votes vote down vote up
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")) 
Example #2
Source File: authentication.py    From cloudify-manager with Apache License 2.0 6 votes vote down vote up
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 
Example #3
Source File: Users.py    From LuckyCAT with GNU General Public License v3.0 5 votes vote down vote up
def correct_password(email, password):
    user = User.objects.get(email=email)
    return utils.verify_password(password, user.password) 
Example #4
Source File: apiservice.py    From crestify with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #5
Source File: test_hashing.py    From flask-security with MIT License 5 votes vote down vote up
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")) 
Example #6
Source File: test_hashing.py    From flask-security with MIT License 5 votes vote down vote up
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")) 
Example #7
Source File: test_hashing.py    From flask-security with MIT License 5 votes vote down vote up
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")) 
Example #8
Source File: test_hashing.py    From flask-security with MIT License 5 votes vote down vote up
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"))) 
Example #9
Source File: oauth2.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def authenticate_user(self, username, password):
        user = User.objects(email=username).first()
        if user and verify_password(password, user.password):
            return user 
Example #10
Source File: server.py    From flask-restless-security with MIT License 5 votes vote down vote up
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 
Example #11
Source File: user_role_db_interface.py    From FACT_core with GNU General Public License v3.0 5 votes vote down vote up
def password_is_correct(self, user_name, password):
        user = self.find_user(email=user_name)
        return verify_password(password, user.password)