Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mainConnection.java
- package database;
- import java.nio.charset.StandardCharsets;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- public class mainConnection {
- public static void main(String[] args ) throws Exception {
- //getConnection();
- }
- public static Connection getConnection() throws Exception{
- try {
- String driver = "com.mysql.cj.jdbc.Driver";
- String url = "jdbc:mysql://localhost:3306/spmproject?serverTimezone=UTC";
- String username = "root";
- String password = "";
- Class.forName(driver);
- Connection conn = DriverManager.getConnection(url,username,password);
- System.out.println("Connected");
- return conn;
- } catch (Exception e) {
- System.out.println(e);
- }
- return null;
- }
- public static String hash(String password) throws NoSuchAlgorithmException {
- MessageDigest md = MessageDigest.getInstance("MD5");
- byte[] hashInBytes = md.digest(password.getBytes(StandardCharsets.UTF_8));
- StringBuilder sb = new StringBuilder();
- for (byte b : hashInBytes) {
- sb.append(String.format("%02x", b));
- }
- return(sb.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement