Advertisement
Guest User

Untitled

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