pyg2fa / demo /

#never ever use this code in your production 
#This is meant to very simplistic example just to show the flow
#Encrypt before saving password and seed in DB 

from bottle import get, post, request
from bottle import route, run
from bottle import redirect
from bottle import response
import pyg2fa

def login_form():
    return '''<form method="POST" action="/login">
                name:<input name="name"     type="text" />
                password:<input name="password" type="password" />    
                <input type="submit" />         

def login_submit():
    name     = request.forms.get('name')
    password = request.forms.get('password')
    if check_login(name, password):
    	response.set_cookie("g2fa_account", name, secret='somesecretkey')
        return "<p>Login failed</p>"

def otp_form():
	name = request.get_cookie("g2fa_account", secret='somesecretkey')
	if name:
		return '''<form method="POST" action="/otp">
		otp:<input name="otp" type="otp" />
		<input type="submit" />               
def logout():
	name = request.get_cookie(("g2fa_account"), secret='somesecretkey')

def otp_form():
   otp     = request.forms.get('otp')
   name = request.get_cookie("g2fa_account", secret='somesecretkey')
   if check_otp(name, otp):
		return "Hello %s. Welcome back. <a href='/logout'>logout</a>" % name
		return "<p>Login Failed</p>"

def check_login(name, password):
	for a in dummyDB():
		if a['user']==name and a['password'] == password:
			return True
			return False

def check_otp(name, otp):
	for a in dummyDB():
		if a['user']==name:
	if pyg2fa.validate(USER_SECRET_INITIAL_OTP_SEED, int(otp), 4):
		return True
		return False

def dummyDB():
	return [{"user":"thej","password":"notsafe", "otp_seed":"KKK67SDNLXIOG65U"},{"user":"ram","password":"yeahokay", "otp_seed":""}]

run(host='localhost', port=8080, debug=True)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.