[Tutor] CGI problem.

Kent Johnson kent_johnson at skillsoft.com
Tue Nov 9 18:52:51 CET 2004


At 07:06 PM 11/9/2004 +0200, Mark Kels wrote:
>On Mon, 08 Nov 2004 18:49:28 -0500, Kent Johnson
><kent_johnson at skillsoft.com> wrote:
> > At 09:40 PM 11/8/2004 +0200, Mark Kels wrote:
> > >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...
> >
> > I just noticed the md5 function hexdigest(). If you use this instead of
> > digest() you will get a nice clean hex string right at the start and
> > dispense with all this \x and repr() stuff.
> >
> >
> >
> > Kent
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>It works!!
>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)
>    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!!



More information about the Tutor mailing list