Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AccountChecker
- {
- public static void main(String[] args)
- {
- if (args.length < 2)
- {
- System.out.println("3");
- return;
- }
- String username = args[0];
- String password = args[1];
- CheckAccount checkAccount = new CheckAccount(username, password);
- checkAccount.validate();
- }
- }
- public class CheckAccount
- {
- static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";
- String foundtoken = "";
- private String username;
- private String password;
- CheckAccount(String user, String pass)
- {
- this.username = user;
- this.password = pass;
- }
- public void validate()
- {
- try
- {
- String url = "https://account.mojang.com/login";
- URL obj = new URL(url);
- HttpsURLConnection con = (HttpsURLConnection)obj.openConnection();
- CookieHandler.setDefault(new CookieManager());
- BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- String token = new String();
- Pattern MY_PATTERN = Pattern.compile("name=\"authenticityToken\" value=\"([a-f0-9]+)\"");
- String inputLine;
- while ((inputLine = in.readLine()) != null)
- {
- Matcher m = MY_PATTERN.matcher(inputLine);
- if (m.find()) {
- token = m.group(1);
- }
- }
- List<String> cookies = new ArrayList();
- cookies = (List)con.getHeaderFields().get("Set-Cookie");
- in.close();
- con.disconnect();
- obj = new URL(url);
- con = (HttpsURLConnection)obj.openConnection();
- con.setRequestMethod("POST");
- con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
- con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
- String urlParameters = "authenticityToken=" + token + "&username=" + this.username + "&password=" + this.password;
- con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- con.setRequestProperty("Content-Length", Integer.toString(urlParameters.length()));
- con.setDoOutput(true);
- DataOutputStream wr = new DataOutputStream(con.getOutputStream());
- wr.writeBytes(urlParameters);
- wr.flush();
- wr.close();
- con.connect();
- Pattern MY_PATTERN2 = Pattern.compile("href=\"/me/renameProfile/([a-f0-9]+)\">Change</a>");
- in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- StringBuffer response = new StringBuffer();
- while ((inputLine = in.readLine()) != null)
- {
- response.append(inputLine);
- Matcher m = MY_PATTERN2.matcher(inputLine);
- if (m.find())
- {
- token = m.group(1);
- this.foundtoken = token;
- }
- }
- in.close();
- if (response.toString().contains("To confirm your identity, please answer the questions below."))
- {
- System.out.println("1");
- return;
- }
- if (this.foundtoken != "") {
- System.out.println("2");
- } else {
- System.out.println("0");
- }
- }
- catch (IOException e)
- {
- System.out.println("3");
- }
- }
- }
Add Comment
Please, Sign In to add comment