Skip to content

Instantly share code, notes, and snippets.

@CubexX
Created March 10, 2018 13:28
Show Gist options
  • Save CubexX/5cdd15dfb9ac59ced815891e42edc8fb to your computer and use it in GitHub Desktop.
Save CubexX/5cdd15dfb9ac59ced815891e42edc8fb to your computer and use it in GitHub Desktop.
Python flask login
CONFIG['password'] = 'PASS'
def login_required(func):
def wrapper(*args, **kwargs):
if not session or session['hash'] != generate_hash(CONFIG['password']):
return redirect('/login')
else:
return func(*args, **kwargs)
wrapper.__name__ = func.__name__
return wrapper
#########
@app.route('/login', methods=['GET', 'POST'])
def login_view():
if request.method == 'POST':
session['hash'] = generate_hash(request.form['password'])
if session['hash'] == generate_hash(CONFIG['password']):
return redirect('/')
else:
return redirect('/login')
return render_template('login.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment