login issue
<%@ page import="java.sql.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.io.*" %>
<%
String username=request.getParameter("username");
String password=request.getParameter("password");
out.println(password);
String connectionURL = "jdbc:mysql://localhost:3306/jsplogin?user=root;password=";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance ();
connection = DriverManager.getConnection(connectionURL, "", "");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM jsplogin WHERE username='"+username+"'");
rs.first();
String temp=rs.getString("password");
out.println(temp==password);
if (temp==password) {
response.sendRedirect("correct.htm");
}else
{
}
rs.close();
%>
To simulate a simple login, i need to open a database connection, then connect to database, and compare wheather the user name and password match. Now the problem is, the executed statement whenever compared to the password post from a form, it returns a false value, which will never be authenticated, why, any solution??
|