As part of my dissertation thesis I have constructed a "bot" that crawls the official forum of the course Programming in C and searches for frequently asked questions in order to post a reply. I am at the part that I must simulate the login in order to be able to post the appropriate reply. The login form is as follows:
!-- login form -- form action="login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)"> script type="text/javascript" src="clientscript/vbulletin_md5.js?v=385"> table cellpadding="0" cellspacing="3" border="0"> tr> td class="smallfont" style="white-space: nowrap;">Όνομα χρήστη td>
td class="smallfont" nowrap="nowrap">Αυτόματη Σύνδεση /tr> tr> td class="smallfont">Κωδικός td> td> /tr> /table>
input type="hidden" name="s" value="" /> input type="hidden" name="securitytoken" value="guest" /> input type="hidden" name="do" value="login" /> input type="hidden" name="vb_login_md5password" /> input type="hidden" name="vb_login_md5password_utf" /> /form> !-- / login form -->
I have come to understand that i need to md5 hash the password but I cannot login whatsoever. I use the post method and i prepare the content doing the following:
content = "do=login&url=login.php" + "&vb_login_md5password=" + md5_pass+ "&vb_login_md5password_utf="+ md5_pass + "&s=&securitytoken=guest&vb_login_username=" + UserName + "&vb_login_password=" + PassWprd;
I then send the contend by doing the following:
urlConnection = (HttpURLConnection)(new URL(targetUrl).openConnection());
// Specifying that we intend to use this connection for input
urlConnection.setDoInput(true);
// Specifying that we intend to use this connection for output
urlConnection.setDoOutput(true);
// Specifying the method of HTTP request which is POST
// throws ProtocolException
urlConnection.setRequestMethod("POST");
// Specifying the content type of our post
urlConnection.setRequestProperty("Content-Type", POST_CONTENT_TYPE);
urlConnection.setRequestProperty("Content-length",String.valueOf (content.length()));
// urlConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");
// Prepare an output stream for writing data to the HTTP connection
// throws IOException
dataOutputStream = new DataOutputStream(urlConnection.getOutputStream());
dataOutputStream.writeBytes(content);
Nonetheless, I cannot login. I believe that I have something wrong at the form that I send but I cannot find what. Any help would be appreciated as I have to finish the program in a few days.