<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV><FONT face=Arial size=2>I'm trying to automatically log into a site and store the resulting html using python. The site uses a form and encrypts the password with some kind of md5 hash.<BR><BR>This is the important parts of the form:</FONT></DIV>
<DIV><BR><FONT face=Arial size=2><script language="JavaScript" src="/<STRONG>admin/javascript/md5.js</STRONG>"></script><BR><script language="JavaScript"><!--<BR>var pskey = "770F11B12EBB7D15058170FA3AD12E685D3A46112B841B1E7BE375F600E62705";<BR>//--><BR></script><BR><BR><form name="LoginForm" action="/guardian/home.html" method="POST" target="_top" onsubmit="<STRONG>doStudentLogin(this)</STRONG>;"><BR><BR><input type="hidden" name="pstoken" value="3895"><BR><input type="text" name="account" value="" size="35"><BR><input type="password" name="pw" value="" size="35"><BR><input type="image" src="/images/btn_enter.gif" width="89" height="27" border="0" alt="Enter"><BR><BR></form><BR><BR>This is the function called in md5.js:<BR><STRONG><FONT size=1>function doStudentLogin(form)<BR>{<BR>var pw = form.pw.value;<BR>var pw2 = pw; // Save a copy of the password preserving case<BR>pw =
pw.toLowerCase();<BR>form.pw.value = hex_hmac_md5(pskey, pw);<BR>if (form.ldappassword!=null) {<BR>// LDAP is enabled, so send the clear-text password<BR>// Customers should have SSL enabled if they are using LDAP<BR>form.ldappassword.value = pw2; // Send the unmangled password<BR>}<BR>return true;<BR>}</FONT></STRONG></FONT></DIV>
<DIV><STRONG><FONT face=Arial size=2></FONT></STRONG> </DIV>
<DIV><FONT face=Arial size=2>I am not sure what the ldappassword is or does. Can some one explain that?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Here's my code :</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=1><STRONG>from urllib import urlopen, urlencode<BR>import re<BR>import hmac</STRONG></FONT></DIV>
<DIV><FONT size=1><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=1><STRONG>account = 'account'<BR>psw = 'my password''<BR>url = "</STRONG></FONT><A href="http://ps.pvcsd.org/guardian/home.html"><FONT size=1><STRONG>http://ps.pvcsd.org/guardian/home.html</STRONG></FONT></A><FONT size=1><STRONG>"</STRONG></FONT></FONT></DIV>
<DIV><FONT size=1><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=1><STRONG>homepagetxt = urlopen("</STRONG></FONT><A href="http://ps.pvcsd.org%22).read/"><FONT size=1><STRONG>http://ps.pvcsd.org").read</STRONG></FONT></A><FONT size=1><STRONG>()</STRONG></FONT></FONT></DIV>
<DIV><FONT face=Arial size=1><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face=Arial size=1><STRONG># get key and pstoken from login page</STRONG></FONT></DIV>
<DIV><FONT face=Arial size=1><STRONG>m = re.search('<input type="hidden" name="pstoken" value="(?P<id>[0-9]+)"', homepagetxt)<BR>token = m.group('id')</STRONG></FONT></DIV>
<DIV><FONT size=1><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face=Arial size=1><STRONG>m = re.search('var pskey = "(?P<id>[a-zA-Z0-9]+)"', homepagetxt)<BR>key = m.group('id')</STRONG></FONT></DIV>
<DIV><FONT face=Arial size=1><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face=Arial size=1><STRONG>hobj = hmac.new(key, psw)<BR>psw = hobj.hexdigest() # encrypt the password</STRONG></FONT></DIV>
<DIV><FONT size=1><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face=Arial size=1><STRONG>data = { 'pstoken' : token, 'account' : account, 'pw' : psw }<BR>e = urlencode(data)</STRONG></FONT></DIV>
<DIV><FONT size=1><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face=Arial size=1><STRONG>page = urlopen(url, e)<BR>txt = page.read()</STRONG></FONT></DIV>
<DIV><FONT size=1><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face=Arial size=1><STRONG>f = open("text.html", 'w')<BR>f.write(txt)<BR>f.close()</STRONG></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>This doesn't however, it just sends me back to the main login page, doenst say invalid password or anything. I've checked, yes the python hmac hash function produces the same results (encrypted password) as the md5.js file. Does anyone know what I am doing wrong??</FONT></DIV></td></tr></table><br>