INNER CODE UNIT · Python

login

metafy-social/python-scripts · scripts/Authentication System using Flask/main.py:60

def login():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if bcrypt.check_password_hash(user.password, form.password.data):
                login_user(user)
                return redirect(url_for('dashboard'))
            else:
                flash("Incorrect Password! Please Try again")
        else:
            flash("This email is not registered. Try Signing Up!")

    return render_template('login.html', form=form)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…