Advertisement
Guest User

Untitled

a guest
Aug 19th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1.  
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.io.PrintStream;
  7. import java.net.URL;
  8. import java.net.URLConnection;
  9. import java.security.MessageDigest;
  10.  
  11. public class LauncherController
  12. {
  13. private String salt = "ton salt";
  14. private String host = "www.tonsite";
  15. private Boolean debug = Boolean.valueOf(false);
  16. public String username;
  17. public String password;
  18.  
  19. public LauncherController(String username, String password)
  20. {
  21. this.username = username;
  22. this.password = password;
  23. }
  24.  
  25. private String getResultFromAPI()
  26. {
  27. StringBuilder a = new StringBuilder();
  28. try
  29. {
  30. URL uri = new URL(
  31. "http://" + this.host +
  32. "/launcher/login/" + this.username +
  33. "/" + this.password +
  34. "/" + this.salt);
  35.  
  36.  
  37. URLConnection ec = uri.openConnection();
  38. BufferedReader in = new BufferedReader(new InputStreamReader(ec.getInputStream(), "UTF-8"));
  39. String inputLine;
  40. while ((inputLine = in.readLine()) != null)
  41. {
  42. String inputLine;
  43. a.append(inputLine);
  44. }
  45. in.close();
  46. if (this.debug.booleanValue()) {
  47. System.out.println("[LauncherController] Value : " + a.toString() + " for the couple username/password : " +
  48. this.username + "/" + this.password + " and salt : " + this.salt);
  49. }
  50. }
  51. catch (IOException e)
  52. {
  53. e.printStackTrace();
  54. }
  55. return a.toString();
  56. }
  57.  
  58. public boolean checkPlayerAccount()
  59. {
  60. String result = getResultFromAPI();
  61. if (result.equals("true")) {
  62. return true;
  63. }
  64. return false;
  65. }
  66.  
  67. public static String sha256(String base)
  68. {
  69. try
  70. {
  71. MessageDigest digest = MessageDigest.getInstance("SHA-256");
  72. byte[] hash = digest.digest(base.getBytes("UTF-8"));
  73. StringBuffer hexString = new StringBuffer();
  74. for (int i = 0; i < hash.length; i++)
  75. {
  76. String hex = Integer.toHexString(0xFF & hash[i]);
  77. if (hex.length() == 1) {
  78. hexString.append('0');
  79. }
  80. hexString.append(hex);
  81. }
  82. return hexString.toString();
  83. }
  84. catch (Exception ex)
  85. {
  86. throw new RuntimeException(ex);
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement