Guest User

Untitled

a guest
Sep 7th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. String url = "jdbc:mysql://localhost:3306/";
  2. String dbName = "myDatabase";
  3. String driver = "com.mysql.jdbc.Driver";
  4. String userName = "root";
  5. String password = "candy";
  6. String userNameE = jTextField1.getText();
  7. String passwordE = new String(jPasswordField1.getPassword());
  8. String passwordF;
  9. // String passwordCheck = null;
  10. String userNameCheck = null;
  11. boolean loginFail = true;
  12. Connection con = null;
  13.  
  14. try {
  15. con = DriverManager.getConnection(url+dbName,userName,password);
  16. System.out.println("Connected to the database");
  17. Statement st = con.createStatement();
  18. ResultSet rt = st.executeQuery("SELECT* FROM accounts WHERE (username='"+userNameE+"') AND AES_DECRYPT(password,'enigma');");
  19. while(rt.next()){
  20. passwordF = rt.getString("password");
  21. userNameCheck = rt.getString("username");
  22. // passwordCheck = rt.getString("password");
  23. accessLevel = rt.getInt(2);
  24. if (userNameCheck.equals(userNameE) && passwordF.equals(passwordE)) {
  25. con.close();
  26.  
  27. if(accessLevel == 1){
  28. mu.setVisible(true);
  29. mu.jButton1.setEnabled(false);
  30. mu.jButton2.setEnabled(false);
  31. loginFail = false;
  32. con.close();}
  33. if(accessLevel == 2){
  34. mu.setVisible(true);
  35. mu.jButton5.setEnabled(false);
  36. loginFail = false;
  37. con.close();
  38. }
  39. System.out.println("Disconnected from database");
  40. this.dispose();
  41. }
  42.  
  43. }
  44.  
  45. } catch (SQLException e) {System.err.println("ERROR: " + e.getMessage()); }
  46. if (loginFail == true){
  47. new aquarium.confirmations.LoginError().setVisible(true);
  48. this.dispose();
  49. }
Add Comment
Please, Sign In to add comment