Mike Firkser
Rutgers '84
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Mike Firkser
Rutgers '84
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Originally posted by Nicholas Cheung:
The condition inside the while loop should be:
rs.next() is a void method, and it just shift the pointers to the record list right with one object, so that you get the next record.
Nick.
James Carman, President<br />Carman Consulting, Inc.
Originally posted by Taz Coello:
I've created a JSP page that prompts the user to login with user name and password. This is then forwarded to "processLogin.jsp" (below) which uses the authenticate method from "Login.java" class (also below). It kind of works- kind of meaning it lets everyone and anyone login even if their details are not stored in the database!!
can someone read over my code and see why this is happening.
processLogin : -
<%@ page import="java.util.*" %>
<jsp:useBean id="tryTo" class="login.Login" scope="request">
<jsp:setProperty name="tryTo" property="*"/>
</jsp:useBean>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if (tryTo.authenticate(username, password)) {
%>
<jsp:forward page="welcome.jsp"/>
<%
} else {
%>
<jsp:forward page="tryAgain.jsp"/>
<%
}
%>
=======================================================================
Login.java : -
package login;
import java.sql.*;
public class Login
{
private String username = "";
private String password = "";
public Login()
{
}
public void setUsername(String username)
{
this.username = username;
}
public void setPassword(String password)
{
this.password = password;
}
public boolean authenticate(String username2,
String password2)
{
String query="select * from Administrator WHERE aUserName LIKE '"+username2+"' AND aPassword LIKE '"+password2+"'";
String aUserName="";
String aPassword="";
String finalUser="";
try
{
Driver drv = (Driver)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection ("jdbc dbc:mcaiymu2", "", "");
Statement stmt = conn.createStatement();
ResultSet myResults=stmt.executeQuery(query);
while(myResults.next())
{
aUserName=myResults.getString("aUserName");
aPassword=myResults.getString("aPassword");
if (username2.equals(aUserName) &&
password2.equals(aPassword))
{
break;
}
}
return true;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
}
============================================================
Also, Does someone know how i can implement session with this?
James Carman, President<br />Carman Consulting, Inc.
Consider Paul's rocket mass heater. |