Here is a piece of code which I have written to perform login operation using Web-Application in java
Here is how I am taking input from user...
String name = req.getParameter("nm");
String passwd = req.getParameter("pswd");
after that I am validating username and password using such piece of code but though I am providing valid username and password (which exists in database) it's telling that's invalid
con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/java_test", "root", "");
Statement statement = con.createStatement();
ResultSet results = statement.executeQuery("SELECT * FROM registration");
int count = 0;
while (results.next()) {
String db_name =results.getString("firstName");
String db_password = results.getString("password");
if ( db_name==name && db_password==passwd ) {
// user is valid
out.print(results.getString("firstName")+"->");
out.println(results.getString("password"));
count++;
}
}
if ( count==0 ) {
out.println("Invalid User name or Password");
}
Everything is going right, no exception is there, while loop is also iterating but somehow if condition (which validates username and password) is not getting satisfied.
Can anyone tell me where and how it's going wrong?