views:

105

answers:

2

Hi, I've got a program I would like to use to input a password and one or multiple strings from a web page. The program takes the strings and outputs them to a time-datestamped text file, but only if the password matches the set MD5 hash.

The problems I'm having here are that

  • I don't know how to get this code on the web. I have a server, but is it as easy as throwing pytext.py onto my server?
  • I don't know how to write a form for the input to this script and how to get the HTML to work with this program. If possible, it would be nice to make it a multi-line input box... but it's not necessary.
  • I want to return a value to a web page to let the user know if the password authenticated successfully or failed.

dtest

import sys
import time
import getopt
import hashlib

h = hashlib.new('md5')
var = sys.argv[1]
print "Password: ", var
h.update(var)
print h.hexdigest()
trial = h.hexdigest()
check = "86fe2288ac154c500983a8b89dbcf288"

if trial == check:
 print "Password success"

 time_stamp = time.strftime('%Y-%m-%d_%H-%M-%S', (time.localtime(time.time())))
 strFile = "txt_" + str(time_stamp) + ".txt"
 print "File created: txt_" + str(time_stamp) + ".txt"

 #print 'The command line arguments are:'
 #for i in sys.argv:
  #print i

 text_file = open(strFile, "w")
 text_file.write(str(time_stamp) + "\n")
 for i in range(2, len(sys.argv)):
  text_file.write(sys.argv[i] + "\n")
  #print 'Debug to file:', sys.argv[i]
 text_file.close()
else:
 print "Password failure"
+1  A: 

Take a look at django. It's an excellent web framework that can accomplish exactly what you are asking. It also has an authentication module that handles password hashing and logins for you.

Christian Oudard
+2  A: 

You'll need to read up on mod_python (if you're using Apache) and the Python CGI module.

ezod