#!/usr/local/bin/python3.3 import cgi import cgitb import pymysql import hashlib import http.cookies as Cookie from functions import get_cookies cgitb.enable() """ The following issues need to be addressed: -reset password -create account """ data = [] #data should be in the order: user, passwd, host, db with open('./dbinfo.txt') as f: for line in f: line = line.strip('\n') data.append(line) info = [] for item in data: item = item.split(':') info.append(item) user=info[0][1] passwd=info[1][1] host=info[2][1] db=info[3][1] def runQuery(query, user, passwd): connection = pymysql.connect(host=host,db=db,user=user,passwd=passwd) cursor = connection.cursor() cursor.execute(query) res = cursor.fetchall() cursor.close() connection.close() if len(res) > 0: return res else: return None #get the form data (it will all be "nonetype" until someone hits 'submit') form = cgi.FieldStorage() cookie = get_cookies() if cookie != None: print("Location: home.py") print("Content-type: text/html\n") else: #extract specific fields from the form uname = form.getvalue("uname") pword = form.getvalue("pword") if pword != None: pword = hashlib.md5(pword.encode()).hexdigest() q1 = """select uid, username, pword_hash, firstname, lastname, admin, approved from User WHERE username LIKE '%s' and pword_hash LIKE '%s';""" %(uname, pword) if uname == None or pword == None: print("Content-type: text/html\n") print("""