[Tutor] CGI problem.

Mark Kels mark.kels at gmail.com
Mon Nov 8 20:40:08 CET 2004


On Mon, 8 Nov 2004 21:35:29 +0200, Mark Kels <mark.kels at gmail.com> wrote:
> On Mon, 08 Nov 2004 10:34:46 -0500, Kent Johnson
> 
> 
> <kent_johnson at skillsoft.com> wrote:
> > 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
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> Sorry, it doesn't work...
> Here is what I get when I'm printing filepass and repr(userpass):
> \xc8\xff\xe9\xa5\x87\xb1&\xf1R\xed=\x89\xa1F\xb4E      (filepass)
> ' ,\xb9b\xacY\x07[\x96K\x07\x15-#Kp'      (repr(userpass))
> 

Oops...
I'm sorry about the last post, I was cmparing 124 and 123.
here is what I get when I do it right (124 and 124):
\xc8\xff\xe9\xa5\x87\xb1&\xf1R\xed=\x89\xa1F\xb4E      (filepass)
'\xc8\xff\xe9\xa5\x87\xb1&\xf1R\xed=\x89\xa1F\xb4E'      (repr(userpass))
Now its easy to just take off the ' chars from the string, and I hope
it will work...


More information about the Tutor mailing list