[Tutor] CGI problem.

Kent Johnson kent37 at tds.net
Tue Nov 9 18:08:48 CET 2004


Mark Kels wrote:
> It works!!

Congratulations!

One small comment below:

> Here is the complete (and working) code:
> 
> import cgi
> import cgitb; cgitb.enable()
> import md5
> import re
> form = cgi.FieldStorage()
> x=open("pass.txt","r")
> form.getfirst("pass")
> print "Content-type: text/html\n\n"
> def printhtml():
>    print """
>       <html><body>
>       <form><input name="pass" type="text"></form>
>       """
> def checkpass():
>    filepass=x.readline() # The password in the file is already digested.
>    userpass=md5.new(form.getfirst("pass")).digest()
>    userpass=repr(userpass)
>    userpass=re.sub("'","",userpass)

userpass = userpass[1:-1] might be a better choice here, in case the 
actual hash includes a ' character.

Kent

>    if userpass==filepass:
>        print "OK, come in."
>    else:
>        print "Wrong password, try again!"
> 
> 
>    
> printhtml()
> if form.has_key("pass"):
>    checkpass()
> x.close()
> 
> Thanks to all who helped me!!
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list