public void login() throws ProtocolException, IOException {
//the variables vB wants
String vb_login_username = "", vb_login_password = "", vb_login_md5password = "", vb_login_md5password_utf = "", cookieuser = "", securitytoken = "";
//set the variables
vb_login_username = username + ""; //the +"" part makes a new instance instead of using
vb_login_password = password + ""; //the same one as the password/username variables
try {
vb_login_md5password = encrypt(password, false);
} catch (NoSuchAlgorithmException e) { System.out.println(e.getMessage()); }
try {
vb_login_md5password_utf = encrypt(password, true);
} catch (NoSuchAlgorithmException e) { System.out.println(e.getMessage()); }
cookieuser = "1";
securitytoken = "1326c99506a80b48ba40754596efd221"; //snipped from my cookies
//set the request properties
httpConn.setRequestProperty("vb_login_username", vb_login_username);
httpConn.setRequestProperty("vb_login_password", vb_login_password);
httpConn.setRequestProperty("vb_login_md5password", vb_login_md5password);
httpConn.setRequestProperty("vb_login_md5password_utf", vb_login_md5password_utf);
httpConn.setRequestProperty("cookieuser", cookieuser);
httpConn.setRequestProperty("do", "login");
httpConn.setRequestProperty("securitytoken", securitytoken);
httpConn.setRequestMethod("POST");
//urlConn.setRequestMethod("POST");
System.out.println(httpConn.getResponseCode() + ": " + httpConn.getResponseMessage());
for (int a = 0; a < 10; a++) {
System.out.println(httpConn.getHeaderFieldKey(a) + " " + httpConn.getHeaderField(a));
}
}
/**
* encrypts the string to MD5
*
* @param plaintext The string to be encrypted
* @param useUTF Should it do the UTF thingy?
* @returns the encrypted string
*/
public String encrypt(String plaintext, boolean useUTF) throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) { System.out.println(e.getMessage()); }
if (useUTF) {
try {
md.update(plaintext.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) { System.out.println(e.getMessage()); }
}
byte raw[] = md.digest(); //step 4
String hash = (new BASE64Encoder()).encode(raw); //step 5
return hash; //step 6
}