Guest User

Untitled

a guest
Aug 2nd, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. public class AccountChecker
  2. {
  3. public static void main(String[] args)
  4. {
  5. if (args.length < 2)
  6. {
  7. System.out.println("3");
  8. return;
  9. }
  10. String username = args[0];
  11. String password = args[1];
  12.  
  13. CheckAccount checkAccount = new CheckAccount(username, password);
  14. checkAccount.validate();
  15. }
  16. }
  17.  
  18.  
  19. public class CheckAccount
  20. {
  21. 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";
  22. String foundtoken = "";
  23. private String username;
  24. private String password;
  25.  
  26. CheckAccount(String user, String pass)
  27. {
  28. this.username = user;
  29. this.password = pass;
  30. }
  31.  
  32. public void validate()
  33. {
  34. try
  35. {
  36. String url = "https://account.mojang.com/login";
  37.  
  38. URL obj = new URL(url);
  39.  
  40. HttpsURLConnection con = (HttpsURLConnection)obj.openConnection();
  41.  
  42.  
  43. CookieHandler.setDefault(new CookieManager());
  44.  
  45.  
  46. BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  47.  
  48. String token = new String();
  49. Pattern MY_PATTERN = Pattern.compile("name=\"authenticityToken\" value=\"([a-f0-9]+)\"");
  50. String inputLine;
  51. while ((inputLine = in.readLine()) != null)
  52. {
  53. Matcher m = MY_PATTERN.matcher(inputLine);
  54. if (m.find()) {
  55. token = m.group(1);
  56. }
  57. }
  58. List<String> cookies = new ArrayList();
  59. cookies = (List)con.getHeaderFields().get("Set-Cookie");
  60. in.close();
  61.  
  62.  
  63.  
  64. con.disconnect();
  65. obj = new URL(url);
  66. con = (HttpsURLConnection)obj.openConnection();
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. con.setRequestMethod("POST");
  74. 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");
  75. con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  76.  
  77. String urlParameters = "authenticityToken=" + token + "&username=" + this.username + "&password=" + this.password;
  78.  
  79.  
  80. con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  81.  
  82. con.setRequestProperty("Content-Length", Integer.toString(urlParameters.length()));
  83.  
  84. con.setDoOutput(true);
  85. DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  86. wr.writeBytes(urlParameters);
  87. wr.flush();
  88.  
  89. wr.close();
  90. con.connect();
  91.  
  92.  
  93. Pattern MY_PATTERN2 = Pattern.compile("href=\"/me/renameProfile/([a-f0-9]+)\">Change</a>");
  94.  
  95. in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  96.  
  97. StringBuffer response = new StringBuffer();
  98. while ((inputLine = in.readLine()) != null)
  99. {
  100. response.append(inputLine);
  101.  
  102. Matcher m = MY_PATTERN2.matcher(inputLine);
  103. if (m.find())
  104. {
  105. token = m.group(1);
  106.  
  107. this.foundtoken = token;
  108. }
  109. }
  110. in.close();
  111. if (response.toString().contains("To confirm your identity, please answer the questions below."))
  112. {
  113. System.out.println("1");
  114. return;
  115. }
  116. if (this.foundtoken != "") {
  117. System.out.println("2");
  118. } else {
  119. System.out.println("0");
  120. }
  121. }
  122. catch (IOException e)
  123. {
  124. System.out.println("3");
  125. }
  126. }
  127. }
Add Comment
Please, Sign In to add comment