Skip to content

Instantly share code, notes, and snippets.

@lorenzobn
Created September 19, 2021 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzobn/5f0b87645a59f46fa1c93d8547a2e8c2 to your computer and use it in GitHub Desktop.
Save lorenzobn/5f0b87645a59f46fa1c93d8547a2e8c2 to your computer and use it in GitHub Desktop.
Snippet of code containing the verification function for 2FA
@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