Advertisement
Guest User

Untitled

a guest
Nov 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. mainConnection.java
  2.  
  3. package database;
  4.  
  5. import java.nio.charset.StandardCharsets;
  6. import java.security.MessageDigest;
  7. import java.security.NoSuchAlgorithmException;
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10.  
  11. public class mainConnection {
  12. public static void main(String[] args ) throws Exception {
  13. //getConnection();
  14. }
  15.  
  16. public static Connection getConnection() throws Exception{
  17. try {
  18. String driver = "com.mysql.cj.jdbc.Driver";
  19. String url = "jdbc:mysql://localhost:3306/spmproject?serverTimezone=UTC";
  20. String username = "root";
  21. String password = "";
  22. Class.forName(driver);
  23.  
  24. Connection conn = DriverManager.getConnection(url,username,password);
  25. System.out.println("Connected");
  26. return conn;
  27. } catch (Exception e) {
  28. System.out.println(e);
  29. }
  30. return null;
  31. }
  32.  
  33. public static String hash(String password) throws NoSuchAlgorithmException {
  34.  
  35. MessageDigest md = MessageDigest.getInstance("MD5");
  36. byte[] hashInBytes = md.digest(password.getBytes(StandardCharsets.UTF_8));
  37.  
  38. StringBuilder sb = new StringBuilder();
  39. for (byte b : hashInBytes) {
  40. sb.append(String.format("%02x", b));
  41. }
  42. return(sb.toString());
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement