Im my system when a user logins in the database decrypts the password and validates. However when I try to run the code, it doesn't seem to validate it.
I think it has to do with the query, I am using Java.
Code:
String url = "jdbc:mysql://localhost:3306/";
String dbName = "myDatabase";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "candy";
String userNameE = jTextField1.getText();
String passwordE = new String(jPasswordField1.getPassword());
String passwordCheck = null;
String userNameCheck = null;
boolean loginFail = false;
Connection con;
try {
con = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
Statement st = con.createStatement();
ResultSet rt = st.executeQuery("SELECT * FROM accounts WHERE username ='"+userNameE+"' AND AES_DECRYPT(password='"+passwordE+"','enigma');");
while(rt.next()){
passwordCheck = rt.getString("password");
userNameCheck = rt.getString("username");
if (passwordCheck.equals(passwordE) && userNameCheck.equals(userNameE)) {
this.dispose();
new Menu().setVisible(true);
loginFail = false;
con.close();
System.out.println("Disconnected from database");
}
}
} catch (SQLException e) {System.err.println("ERROR: " + e.getMessage()); }
if (loginFail == true){
new login.confirmations.LoginError().setVisible(true);
this.dispose();
}