Advertisement
Guest User

Untitled

a guest
May 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5.  
  6. /**
  7. * vBulletin class
  8. *
  9. * @author Mad Turnip
  10. */
  11. public class vBulletin implements Runnable {
  12.  
  13. private Connection connection;
  14. private Statement statement;
  15.  
  16. public enum Type {
  17. myBB,
  18. SMF,
  19. IPB,
  20. vBulletin,
  21. phpBB,
  22. }
  23.  
  24. private String[] tableNames = new String[6];
  25.  
  26. private void setTables() {
  27. if (forum == Type.myBB) {
  28. tableNames = new String[] { "mybb_users", "username", "password", "salt", "usergroupid" };
  29. } else if (forum == Type.SMF) {
  30. tableNames = new String[] { "smf_members", "member_name", "passwd", "passwd", "usergroupid" };
  31. } else if (forum == Type.IPB) {
  32. tableNames = new String[] { "members", "name", "converge_pass_hash", "converge_pass_salt", "mgroup" };
  33. } else if (forum == Type.vBulletin) {
  34. tableNames = new String[] { "user", "username", "password", "salt", "usergroupid" };
  35. } else if (forum == Type.phpBB) {
  36. tableNames = new String[] { "users", "username", "user_password", "user_password", "group_id" };
  37. }
  38. }
  39.  
  40. public vBulletin(String url, String database, String username,
  41. String password, Type forum) {
  42. hostAddress = "jdbc:mysql://" + url + "/" + database;
  43. this.username = username;
  44. this.password = password;
  45. this.forum = forum;
  46. try {
  47. new Thread(this).start();
  48. } catch (Exception e) {
  49. connection = null;
  50. e.printStackTrace();
  51. }
  52. }
  53.  
  54. private final String hostAddress;
  55. private final String username;
  56. private final String password;
  57. private final Type forum;
  58.  
  59. private void connect() {
  60. try {
  61. Class.forName("com.mysql.jdbc.Driver");
  62. } catch (Exception e2) {
  63. System.out.println("Cannot find mySql Driver.");
  64. return;
  65. }
  66. try {
  67. connection = DriverManager.getConnection(hostAddress, username,
  68. password);
  69. statement = connection.createStatement();
  70. } catch (Exception e) {
  71. System.out
  72. .println("Connetion rejected, Wrong username or password, or ip is banned, or host is down.");
  73. connection = null;
  74. e.printStackTrace();
  75. }
  76. }
  77.  
  78. private void ping() {
  79. try {
  80. String query = "SELECT * FROM " + tableNames[0] + " WHERE "
  81. + tableNames[2] + " LIKE 'null312'";
  82. statement.executeQuery(query);
  83. } catch (Exception e) {
  84. connection = null;
  85. connect();
  86. e.printStackTrace();
  87. }
  88. }
  89.  
  90. @Override
  91. public void run() {
  92. boolean allowRun = true;
  93. while (allowRun) {
  94. try {
  95. if (connection == null) {
  96. setTables();
  97. connect();
  98. } else {
  99. ping();
  100. }
  101. Thread.sleep(10000);
  102. } catch (Exception e) {
  103. }
  104. }
  105. }
  106.  
  107. /**
  108. * returns 2 integers, the return code and the usergroup of the player
  109. */
  110. public int[] checkUser(String name, String password) {
  111. int i = 0;
  112. int[] returnCodes = { 0, 0 };// return code for client, group id
  113.  
  114. try {
  115. ResultSet results = null;
  116. String query = "SELECT * FROM " + tableNames[0] + " WHERE "
  117. + tableNames[1] + " LIKE '" + name + "'";
  118. try {
  119. if (statement == null) {
  120. statement = connection.createStatement();
  121. }
  122. } catch (Exception e5) {
  123. statement = null;
  124. connection = null;
  125. connect();
  126. statement = connection.createStatement();
  127. }
  128. results = statement.executeQuery(query);
  129. if (results.next()) {
  130. String salt = results.getString(tableNames[3]);
  131. String pass = results.getString(tableNames[2]);
  132. int group = results.getInt(tableNames[4]);
  133. returnCodes[1] = group;
  134. String pass2 = "";
  135. if (forum == Type.myBB) {
  136. pass2 = MD5.MD5(salt);
  137. pass2 = MD5.MD5(pass2 + password);
  138. } else if (forum == Type.vBulletin) {
  139. pass2 = MD5.MD5(password);
  140. pass2 = MD5.MD5(pass2 + salt);
  141. } else if (forum == Type.SMF) {
  142. pass2 = MD5.SHA((name.toLowerCase()) + password);
  143. } else if (forum == Type.phpBB) {
  144. pass2 = MD5.MD5(password);
  145. } else if (forum == Type.IPB) {
  146. pass2 = MD5.MD5(MD5.MD5(salt) + MD5.MD5(password));
  147. }
  148. if (pass.equals(pass2)) {
  149. returnCodes[0] = 2;
  150. return returnCodes;
  151. } else {
  152. returnCodes[0] = 3;
  153. return returnCodes;
  154. }
  155. } else {
  156. // no user exists
  157. returnCodes[0] = 12;
  158. return returnCodes;
  159. }
  160. } catch (Exception e) {
  161. statement = null;
  162. returnCodes[0] = 8;
  163. return returnCodes;
  164. }
  165. }
  166.  
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement