Advertisement
Guest User

Untitled

a guest
May 15th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.HashMap;
  8.  
  9. /**
  10. * MySQL Class
  11. *
  12. * @author 'Ecstasy?!
  13. */
  14. public class MysqlManager {
  15.  
  16. /**
  17. * Variables
  18. */
  19. public int userGroup;
  20. public int unreadMessages;
  21. public int postCount;
  22. /**
  23. * Instances
  24. */
  25. public static Connection connection;
  26. public static client client;
  27.  
  28. public MysqlManager(client client) {
  29. this.client = client;
  30. }
  31. /**
  32. * Constant variables
  33. */
  34. public static final String URL = "jdbc:mysql://67.220.212.50:3306"; //sec.
  35. public static final String DATABASE = "zynna_Meth";
  36. public static final String USER = "zynna_Meth";
  37. public static final String PASSWORD = "test"; //The old one was correct, however the usernamd and password was wrong.
  38. public static final int ADMIN = 6;
  39. public static final int MOD = 7;
  40. public static final int REGULAR_PLAYER = 2;
  41. public static final int GLOBAL_MOD = 5;
  42. public static final int BANNED_PLAYER = 8;
  43. public static final int DONATOR = 9;
  44.  
  45. /**
  46. * @return the database
  47. */
  48. public static String getDatabase() {
  49. return DATABASE;
  50. }
  51.  
  52. /**
  53. * @return the URL of the database
  54. */
  55. public static String getUrl() {
  56. return URL;
  57. }
  58.  
  59. /**
  60. * @return the username to connect to the database with
  61. */
  62. public static String getUser() {
  63. return USER;
  64. }
  65.  
  66. /**
  67. * @return the password to connect to the database with
  68. */
  69. public static String getPassword() {
  70. return PASSWORD;
  71. }
  72.  
  73. /**
  74. * This basically puts everything together, just to keep it organized.
  75. *
  76. * @return the entire url to connect to the database
  77. */
  78. public static String URL() {
  79. return getUrl() + "/" + getDatabase();
  80. }
  81.  
  82. /**
  83. * Creates a connection to the database.
  84. */
  85. public static void createConnection() {
  86. try {
  87. Class.forName("com.mysql.jdbc.Driver").newInstance();
  88. connection = DriverManager.getConnection(URL(), getUser(),
  89. getPassword());
  90. misc.println_debug("Sucessfully connceted to the database.");
  91. } catch (Exception exception) {
  92. exception.printStackTrace();
  93. }
  94. }
  95.  
  96. public static boolean checkDetails(String username, String password) {
  97. try {
  98. Statement statement = connection.createStatement();
  99. ResultSet group = statement.executeQuery("SELECT * FROM user WHERE username = '"
  100. + username + "'");
  101. if (group.next()) {
  102. String givenPassword = passHash(password, group.getString("salt"));
  103. System.out.println("Loading User: " + username + " Gave Hash: " + givenPassword);
  104. if (givenPassword.equals(group.getString("password"))) {
  105. return true;
  106. }
  107. }
  108. } catch (SQLException e) {
  109. return false;
  110. }
  111. return false;
  112. }
  113.  
  114. /**
  115. * @param name
  116. * the players username
  117. * @param password
  118. * the players password.
  119. * @return true or false, if the name & password is registered on the
  120. * forums.
  121. */
  122. public boolean loadAccount(String name, String password) { //let me look at my source.
  123. try {
  124. Statement statement = connection.createStatement();
  125. ResultSet group = statement.executeQuery("SELECT * FROM user WHERE username = '"
  126. + name + "'");
  127. if (group.next()) {
  128. String pass = group.getString("password");
  129. String salt = group.getString("salt");
  130. userGroup = group.getInt("usergroupid");
  131. unreadMessages = group.getInt("pmunread");
  132. String encryptedPassword = passHash(password, salt);
  133. System.out.println("Loading user: " + name + " Pass: " + pass + " Salt: " + salt + " UG: " + userGroup);
  134. if (pass.equalsIgnoreCase(encryptedPassword)) {
  135. statement.close();
  136. return true;
  137. } else {
  138. statement.close();
  139. return false;
  140. }
  141. }
  142. } catch (Exception e) {
  143. return false;
  144. }
  145. return false;
  146. }
  147.  
  148. /**
  149. * @param name
  150. * The players username This method will load all additional
  151. * info, other than the username and password.
  152. * @Author Ecstasy
  153. */
  154. public void loadInfo(String name) {
  155. try {
  156. Statement statement = connection.createStatement();
  157. ResultSet group = statement.executeQuery("SELECT * FROM user WHERE username = '"
  158. + name + "'");
  159. while (group.next()) {
  160. userGroup = group.getInt("usergroupid");
  161. unreadMessages = group.getInt("pmunread");
  162. postCount = group.getInt("posts");
  163. }
  164. } catch (Exception e) {
  165. System.out.println("Oh fuck.");
  166. }
  167. }
  168.  
  169. /**
  170. * @param in
  171. * the password before it's encrypted
  172. * @param salt
  173. * the encryption of the password (In this case, the vBulletin
  174. * encryption
  175. * @return the encrypted password
  176. */
  177. public static String passHash(String in, String salt) {
  178. String a = new MD5(in).compute();
  179. String b = new MD5(a + salt).compute();
  180. return b;
  181. }
  182.  
  183. /**
  184. * Loads the player rights depending on which <i>'userGroup'</i> the player
  185. * belongs to.
  186. */
  187. public void loadPlayerRights() {
  188. switch (userGroup) {
  189. case DONATOR:
  190. client.donator = 1;
  191. return;
  192. case ADMIN:
  193. client.playerRights = 3;
  194. return;
  195. case MOD:
  196. client.playerRights = 1;
  197. return;
  198. case REGULAR_PLAYER:
  199. client.playerRights = 0;
  200. return;
  201. case GLOBAL_MOD:
  202. client.playerRights = 1;
  203. return;
  204. }
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement