Demo entry 6631021

Login Test


Submitted by anonymous on Jul 12, 2017 at 12:45
Language: Python 3. Code size: 1.1 kB.

from bottle import route, run, template, get, post, request
import hashlib

user = ""
adminpassword = '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918'

def login():
    return '''
        <form action="/login" method="post">
            Username: <input name="username" type="text" />
            Password: <input name="password" type="password" />
            <input value="Login" type="submit" />

@route('/login', method='POST')
def do_login():
    username = request.forms.get('username')
    password = request.forms.get('password')
    if checkpassword(username, password):
        user = username
        return "<p>Your login information was correct. Welcome {}</p>".format(user)
        return "<p>Login failed.</p>"

def checkpassword(user, password):
    if user == "admin":
        if hashlib.sha256(password.encode('utf-8')).hexdigest() == adminpassword:
            return True
        return False

run(host='localhost', port=8080)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).