Here it is in action:
http://bert.stuy.edu/pbrooks/spring2016/materials/intro-2/hidden_login.html
Here is the hidden_login.html file:
<html> <head> <title>Hidden-Login</title> </head> <body> <form action="hidden_demo.py" method="get"> Username: <input name="username" type="text" /><br /> Password: <input name="password" type="password" /><br /> <input name="submit_login" type="submit" value="Login" /><br /> </form> </body> </html>
Here is the hidden_gender.html file:
<html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Hidden Gender</title> </head> <body> All right, ???. Now answer this:<br> <form action="hidden_demo.py" method="get"> Gender: <input name="gender" type="radio" checked="checked" value="female" /> female <input name="gender" type="radio" value="male" /> male<br /> <input type="hidden" name="hidden_username" value="???" /> <input name="submit_gender" type="submit" value="submit" /></form> </body> </html>
Here is the hidden_demo.py program:
#! /usr/bin/python #! /usr/bin/python HTML_top='Content-type: text/html\n\n' Bad_login=HTML_top+'''userame or password problem.
Press the back button to try again.''' Gender_result=HTML_top+'Thank you, ?? ???' import cgi, cgitb cgitb.enable() def main(): form=cgi.FieldStorage() # are we getting this from the login screen? if 'submit_login' in form: username=form.getvalue('username').strip() password=form.getvalue('password').strip() # check for validity if username=='' or password=='': print Bad_login return # here, you can check for a valid username and password, but we won't # get the html file for the gender question html=ReadFile('hidden_gender.html') # replace the "???" with the username html=html.replace('???',username) print HTML_top+html return # are we getting this from the gender form? if 'submit_gender' in form: username=form.getvalue('hidden_username') gender=form.getvalue('gender') html=Gender_result #add in the username html=html.replace('???',username) if gender=='male': html=html.replace('??','Mr.') else: html=html.replace('??','Ms.') print html return print HTML_top+'''debugging''' return def ReadFile(filename): try: f=open(filename,'rU') s=f.read() f.close() except: s='' return s main()