Beispiel #1
0
    def validate(auth_data):
        auth_document = mdb.security.find_one(
            {'username': auth_data.get('username')}, {'_id': 0})
        if auth_document is not None:
            if bcrypt.check_password_hash(auth_document.get('hashed_password'),
                                          auth_data.get('password')):
                return auth_document  # dict

        return None
Beispiel #2
0
def change_password():
    if request.method == "GET":
        return redirect(url_for("my_account"))
    form = ChangePasswordForm()
    if not form.validate():
        return jsonify(error_messages=form.errors), 400
    if not bcrypt.check_password_hash(current_user.password_hash,
                                      form.current_password.data):
        return jsonify(error_messages={
            "current_password": ["Current password is incorrect"],
        }), 400
    current_user.password_hash = \
        bcrypt.generate_password_hash(form.new_password.data).decode("utf-8")
    db.session().commit()
    return ""
Beispiel #3
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('login unsuccessful', 'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #4
0
def login():
    if request.method == "GET":
        return render_template("accounts/login.html", form=LoginForm())
    form = LoginForm(request.form)
    if not form.validate():
        return render_template("accounts/login.html", form=form)
    account = Account.query.filter_by(username=form.username.data).first()
    if account is None or \
            not bcrypt.check_password_hash(
                account.password_hash,
                form.password.data,
            ):
        return render_template(
            "accounts/login.html",
            form=form,
            error="Invalid username or password",
        )
    login_user(account)
    next = request.args.get("next", "")
    if next == "":
        return redirect(url_for("index"))
    return redirect(next)
Beispiel #5
0
def verify_password(provided, password_hash, salt):
    return bcrypt.check_password_hash(password_hash, salt + provided)
def match_hashed_value(plain_value: str, hashed_value: str):
    return bcrypt.check_password_hash(hashed_value, plain_value)
Beispiel #7
0
 def check_password(self, password):
     return bcrypt.check_password_hash(self.password_hash, password)
Beispiel #8
0
def check_password_hash(password_hash, salt, password):
    return bcrypt.check_password_hash(password_hash, salt + password)