How do I verify in the most right way the username and password that were inputted by the user to the database?
In c++, we used to verify by using if-else:
if((user == "username")&&(pass == "password")){
cout<<"You are now logon!";
}
In java-mysql I'm not sure if I'm on the right track:
Login Button
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
user = jTextField1.getText();
pass = jPasswordField1.getPassword();
login();
}
Method/function
private void login() {
try {
if (user != null) {
sql = "Select * from users_table Where username='" + user + "'";
rs = stmt.executeQuery(sql);
rs.next();
username = rs.getString("username");
password = rs.getString("password");
}
}
catch (SQLException err) {
JOptionPane.showMessageDialog(this, err.getMessage());
}
}
If the username and password that inputted by the user matched with the ones in the database then he will be directed to a new jFrame else message dialog will popup saying invalid username or password. Can someone help me with my codes, I don't know how to use the if-else statement with mysql;
Thanks! :)