Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package ichato;
  2.  
  3. import java.security.PublicKey;
  4. import java.sql.*;
  5. import org.mindrot.jbcrypt.BCrypt;
  6.  
  7. public class ConnectBD {
  8. private Connection con;
  9. private Statement st;
  10. private ResultSet rs;
  11. private static final int logRounds=12;
  12.  
  13. public static String hashpw(String password) {
  14. return BCrypt.hashpw(password, BCrypt.gensalt(logRounds));
  15. }
  16.  
  17. public static boolean verifyHash(String password, String hash) {
  18. return BCrypt.checkpw(password, hash);
  19. }
  20.  
  21. public ConnectBD(){
  22. try{
  23. Class.forName("com.mysql.jdbc.Driver");
  24. con= DriverManager.getConnection("jdbc:mysql://localhost:3306/si_test","root","");
  25. st= con.createStatement();
  26. }catch(Exception e){
  27. System.out.println("Error"+e);
  28. }
  29. }
  30. public boolean confirmLogin(String name,String password){
  31. try{
  32. String query="Select hash from user where name="+name;
  33. rs=st.executeQuery(query);
  34. String sHash=rs.getString("hash");
  35. return verifyHash(password,sHash);
  36. }catch(Exception e){
  37. System.out.println("Error"+e);
  38. }
  39. return false;
  40. }
  41.  
  42. /*public PublicKey userPublic(String name){
  43. try{
  44. String query="Select publicKey from user where name="+name;
  45. rs=st.executeQuery(query);
  46. //=rs.getString("publicKey");
  47.  
  48. }catch(Exception e){
  49. System.out.println("Error"+e);
  50. }
  51. }*/
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement