Advertisement
Guest User

Untitled

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