Created
September 19, 2021 08:29
-
-
Save lorenzobn/5f0b87645a59f46fa1c93d8547a2e8c2 to your computer and use it in GitHub Desktop.
Snippet of code containing the verification function for 2FA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route("/login/auth", methods=['GET', 'POST']) | |
def OTP_auth(): | |
if session['username'] == None: | |
return redirect(url_for('login')) | |
if request.method == 'POST': | |
#verify OTP | |
totp_instance = pyotp.TOTP(app.config["OTP_CODE"]) | |
valid = totp_instance.verify(request.form.get("otp")) | |
if valid: | |
return render_template("success.html") | |
else: | |
flash("Invalid code. Please try again.") | |
else: | |
if app.config["OTP_ENABLED"] == "True": | |
return render_template('auth.html') | |
else: | |
app.config["OTP_ENABLED"] = "True" | |
return render_template('auth.html', secret_key=app.config["OTP_CODE"]) | |
return redirect(url_for("OTP_auth")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment