Commit 86563d0a authored by Sorrel Harriet's avatar Sorrel Harriet
Browse files

initial work on a login script

parent ac17b39c
#!/usr/bin/env python3
This script handles the processing
of the login form in the catflucks application.
Note: there is lots of code repetition here...
What could we do about that?
# import modules from Python standard library
import cgi
import cgitb
import bcrypt
# import custom modules
from config import config
import utils
# connect to database
db = utils.db_connect( config )
# get the form data
form = cgi.FieldStorage()
# tell the browser we are sending HTML
print("Content-Type: text/html\n")
# check that login form was submitted
if 'btn_login' in form:
# encrypt the password
pw = form['password'].value
username = form['username'].value
# look for an account with the username
account = db.accounts.find_one({
# check if an account came back
if account is not None:
# if so, compare the unhashed password from the form
# with the hashed version in the database
if bcrypt.checkpw(pw.encode('utf-8'),account['password'].encode('utf-8')):
response = "Hello {}!".format(account['name']['first'])
response = "Wrong password."
response = "Sorry, I don't think I know you!"+username
# for testing only, output response
print("<p>How did you get here? Maybe you want to <a href='/cgi-bin/'>go back home</a>?</p>")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment