• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

what's wrong

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is java bean
import java.sql.*;
public class UserInfoBean {
private String username;
private String password;
private boolean validUsername;
private boolean validPassword;
private String driver="sun.jdbc.odbc.JdbcOdbcDriver";
private String protocol="jdbc dbc:db";

public UserInfoBean() {
try {
Class.forName(driver);
} catch(ClassNotFoundException e) {}
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String email) {
this.password = password;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public boolean isValidUsername() {
return validUsername;
}
public boolean isValidPassword() {
return validPassword;
}
public void registerSupportRequest() throws SQLException
{
Connection connection = null;
String selectUsername = "SELECT MEMBER.USERNAME FROM MEMBER WHERE MEMBER.USERNAME = ?";
try
{
connection = DriverManager.getConnection(protocol);
//verify Username
PreparedStatement pstmt1 =connection.prepareStatement(selectUsername);
pstmt1.setString(1,username);
ResultSet rs1 = pstmt1.executeQuery();
if (rs1.next())
{
validUsername= true;
String user=getUsername();
String password=getPassword();
String selectPassword ="SELECT PASSWORD FROM MEMBER WHERE USERNAME='"+(user)+"' and password='"+(password)+"'";
//verify password
Statement stmt = connection.createStatement();
ResultSet rst2=stmt.executeQuery(selectPassword);
if(rst2.next())
validPassword=true;
else
validPassword=false;
}

else {
validUsername= false;
}
}
finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException sqle) {}
}
}
}
}
Now this the process.jsp file that i call whenever the user logins.
Process.jsp
==============
<%@ page language="java"%>
<%@ page errorPage="error.jsp"%>
<jsp:useBean id="userInfo" scope="session" class="UserInfoBean"/>
<jsp:setProperty name="userInfo" property="*"/>
<% userInfo.registerSupportRequest() ; %>
<% if (userInfo.isValidUsername())
{
if (userInfo.isValidPassword())
{ %>
<jsp:forward page="valid.jsp"/>
<% }
else {%>
<jsp:forward page="invalid1.jsp"/>
<%}
}
else { %>
<jsp:forward page="invalid.jsp"/>
<% } %>
In the above code why do i always get an invalid password even though i enter the correct password.
 
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a newbie to servlets and the like but I did notice your line of code here
public void setPassword(String email) {
this.password = password;
}
My guess is that it should probably be:
public void setPassword(String email) {
this.password = email;
}
//OR maybe this:
public void setPassword(String password) {
this.password = password;
}
Hope that helps
Amber
[This message has been edited by Amber Woods (edited May 25, 2001).]
 
Kavita Ghia
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Amber,
That certainly is a mistake not supposed to be repeated.Thanks for the pointer.
Kavita.
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic