Ok, So I decided to make a login system which will work with Sythe. This can easily be added to your programs to require them to be a Sythe user to login.
Login.java
Demo.java
With a little work this may work with other forums just by changing the values for finding the elements.
You'll need HTMLUnit which is here - http://htmlunit.sourceforge.net/
Login.java
Code:
package org.login;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author iJava
*/
public class Login {
private String username, password, forumPMURL, forumTitile;
public Login(String username, String password, String forumPMURL, String forumTitle) {
this.username = username;
this.password = password;
this.forumPMURL = forumPMURL;
this.forumTitile = forumTitle;
}
public boolean logIn() {
try {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
HtmlPage loggedInPage = null;
HtmlPage sourcePage = webClient.getPage(forumPMURL);
if (sourcePage.getTitleText().equals(forumTitile)) {
HtmlTextInput usernameElement = sourcePage.getElementByName("vb_login_username");
HtmlPasswordInput passwordElement = sourcePage.getElementByName("vb_login_password");
HtmlElement submitBtnElement = sourcePage.getElementByAccessKey('s');
if (usernameElement != null && usernameElement.getText().equals("User Name")) {
usernameElement.setValueAttribute(username);
}
if (passwordElement != null && passwordElement.getText().equals("")) {
passwordElement.setValueAttribute(password);
}
if (loggedInPage == null && usernameElement != null && passwordElement != null && usernameElement.getText().equals(username) && passwordElement.getText().equals(password)) {
try {
loggedInPage = submitBtnElement.click();
} catch (IOException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (loggedInPage != null) {
return (loggedInPage.asText().contains("Thank you for logging in, " + username));
}
}
} catch (IOException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
} catch (FailingHttpStatusCodeException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
return false;
}
}
Demo.java
Code:
package org.demo;
import org.login.Login;
/**
*
* @author iJava
*/
public class Demo {
public static void main(String[] args0) {
Login login = new Login("username", "password", "http://www.Sythe.org/private.php?do=newpm&u=1", "Sythe.Org Forums");
if(login.logIn()) {
System.out.println("We Logged In!");
}
}
}
With a little work this may work with other forums just by changing the values for finding the elements.
You'll need HTMLUnit which is here - http://htmlunit.sourceforge.net/



