#!/Library/Frameworks/Python.framework/Versions/Current/bin/python import cgi, Cookie, os, sha def ProcessName(form): """ Processes name of login form. Returns True if error, else False. """ error = False try: n = form['login'].value except KeyError: print "please enter your name" error = True if not error: print 'welcome ' + n + '\n' return error def ProcessPass(c): """ Processes password of login form. """ print "

your password is " print c['passw'].value def GetCookie(form): """ Retrieves cookie and uses form to update. """ if os.environ.has_key('HTTP_COOKIE'): c = Cookie.Cookie(os.environ['HTTP_COOKIE']) else: c = Cookie.Cookie() if c.has_key('login'): if form.has_key('login'): c['login'] = form['login'].value if c.has_key('passw'): if form.has_key('passw'): p = form['passw'].value d = sha.new(p).hexdigest() c['passw'] = d return c def main(): """ Form to process login. """ form = cgi.FieldStorage() c = GetCookie(form) print c print "Content-type: text/html\n" print "\n" error = ProcessName(form) if not error: ProcessPass(c) print "\n" main()