[Tutor] CGI problem.

Kent Johnson kent_johnson at skillsoft.com
Mon Nov 8 16:34:46 CET 2004


At 05:32 PM 11/8/2004 +0200, Mark Kels wrote:
>I doesn't work :( ...
>Here is what I did :
>
>import cgi
>import cgitb; cgitb.enable()
>import md5
>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()
>    if repr(userpass)==filepass:
>        print "OK, come in."
>    else:
>        print "Wrong password, try again!"
>
>printhtml()
>if form.has_key("pass"):
>    checkpass()
>x.close()
>
>
>the result is the same (out put is always for wrong password...).


I think you need to strip the newline from filepass:
   filepass=x.readline().strip()

If this doesn't work put in
print filepass
print repr(userpass)
so you can see what it is comparing

Kent




More information about the Tutor mailing list