My web login screen does not function correctly

N

Naccessible

I am using Oracle 9i and I have a user login table. It cycles through
trying to match user and password.
More information is below the code snippets. Is the problem Oracle or
Java? Any help is greatly appreciated!

Here is a the code snippets that I use:

This is class loginserverlet:


public class loginserverlet extends HttpServlet {


private String userName = null;
private String passWord = null;
boolean valid = true;
String parmuser = null;
String parmpass = null;


public void doPost(HttpServletRequest login, HttpServletResponse
res)
throws ServletException, IOException {


// userName = login.getParameter("username");
// passWord = login.getParameter("password");


PrintWriter out = res.getWriter ();
SeparateTest newtest = new SeparateTest();
parmuser = newtest.SeparateTest();
out.println(parmuser);
if (parmuser.equals("true")){
// PrintWriter out = res.getWriter();
out.println("inuser value -- " + valid);
//
res.sendRedirect("http://192.168.1.2:12080/GADXML/DevGADXML/DGADpages/biography.html");

}
if (parmuser.equals("false")){
// PrintWriter out = res.getWriter();
out.println(" not valid");
//
res.sendRedirect("http://192.168.1.2:12080/GADXML/DevGADXML/DGADpages/notvalidpass.htm");

}
}



}


This is the SeparateTest class:

public class SeparateTest {
public String uName = null;
public String pWord = null;
public String pmuser = null;
public boolean validtst = true;


public String SeparateTest() {
initLogin logtest = new initLogin();
uName = "david";
pWord = "rachel";
validtst = logtest.authenticate(uName, pWord);
System.out.println(validtst);
if (validtst){
pmuser = "true";
}
else if (!validtst){
pmuser = "false";
}
return pmuser;
}


and this is initLogin class:


public class initLogin {


private String username = "";
private String password = "";


public initLogin() {
}


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 USERS;";
String DbUserName="";
String DbPassword="";
String finalUser="";
String retval = null;


String data = "jdbc:eek:dbc:GADXML";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(data, "system",
"rosetta");
Statement stat = conn.createStatement();
ResultSet rst=stat.executeQuery(query);
StringBuffer testUser = new StringBuffer(username2);
StringBuffer testPass = new StringBuffer(password2);
String testuser = testUser.toString();
String testpass = testPass.toString();


parameterInput chkparm = new parameterInput();
retval = chkparm.readLine(testuser);
username2 = retval;
retval = null;
retval = chkparm.readLine(testpass);
password2 = retval;
retval = null;
System.out.println("username -- " + username2);
System.out.println("password -- " + password2);
while(rst.next())
{
DbUserName=rst.getString("username");
DbPassword=rst.getString("password");
finalUser=rst.getString("usertype");
finalUser=rst.getString("approver");
testUser = new StringBuffer(DbUserName);
testPass = new StringBuffer(DbPassword);
testuser = testUser.toString();
testpass = testPass.toString();


retval = chkparm.readLine(testuser);
DbUserName = retval;
retval = null;
retval = chkparm.readLine(testpass);
DbPassword = retval;
retval = null;
if (username2.equals(DbUserName) &&
password2.equals(DbPassword)) {
return true;
}
}
return true;
}
catch(Exception e){
e.printStackTrace();
System.out.println("here is the problem -- " + DbUserName);
return false;
}
}
}


And parameter input:


public class parameterInput {
String input = null;
public static String readLine(String firstVal){
StringBuffer response = new StringBuffer();
try {
System.out.println("passed value -- " + firstVal);
StringReader buff = new StringReader(firstVal);
int in = 0;
int totval = 0;
int inplace = 0;
int nextplace = 0;
char inChar;
do {
in = buff.read();
inChar = (char) in;
if ((in != -1) && ((inChar != '\n')||(inChar !=
'\t'))){
response.append(inChar);
inplace++;
nextplace = inplace + in;
totval = totval + nextplace;
System.out.println("char: " + inChar + " value: " +

in );
}
} while ((in != -1) & ((inChar != '\n') || (inChar !=
'\t')));
buff.close();
return response.toString();
// return totval;
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
return null;
}
}
}


Here is the TestGad class:


public class testgad {
private String valid = "";
private String passWord = "";
// public static int username = 0;
// public static int password = 0;
public static String username = null;
public static String password = null;
boolean truetest = false;


public testgad() {


System.out.println("newtest");
initLogin logtest = new initLogin();
System.out.println(username);
System.out.println(password);
truetest = logtest.authenticate(username, password);
if (truetest){
System.out.println("its true");
}
if (!truetest){
System.out.println("its not really true");
}


// loginbean logtest = new loginbean();
// logtest.authent2cate(username, password);
}


public static void main(String[] args) {
username = "david";
password = "rachel";
testgad testgad = new testgad();
}
}


This code basically cycles through the oracle user database and
compares passwords for login to either the web, via the loginserverlet
class or from the console using TestGad class. TestGad works fine but
loginserverlet does not. It consistently returns "false" which is not
correct. both classes are "hardcoded with a username and password" so
the results should be the same. Thank you for your response.

N-.

Reply »
 
N

N-.

PROBLEM SOLVED!!! THANKS!

N-.
I am using Oracle 9i and I have a user login table. It cycles through
trying to match user and password.
More information is below the code snippets. Is the problem Oracle or
Java? Any help is greatly appreciated!

Here is a the code snippets that I use:

This is class loginserverlet:


public class loginserverlet extends HttpServlet {


private String userName = null;
private String passWord = null;
boolean valid = true;
String parmuser = null;
String parmpass = null;


public void doPost(HttpServletRequest login, HttpServletResponse
res)
throws ServletException, IOException {


// userName = login.getParameter("username");
// passWord = login.getParameter("password");


PrintWriter out = res.getWriter ();
SeparateTest newtest = new SeparateTest();
parmuser = newtest.SeparateTest();
out.println(parmuser);
if (parmuser.equals("true")){
// PrintWriter out = res.getWriter();
out.println("inuser value -- " + valid);
//
res.sendRedirect("http://192.168.1.2:12080/GADXML/DevGADXML/DGADpages/biography.html");

}
if (parmuser.equals("false")){
// PrintWriter out = res.getWriter();
out.println(" not valid");
//
res.sendRedirect("http://192.168.1.2:12080/GADXML/DevGADXML/DGADpages/notvalidpass.htm");

}
}



}


This is the SeparateTest class:

public class SeparateTest {
public String uName = null;
public String pWord = null;
public String pmuser = null;
public boolean validtst = true;


public String SeparateTest() {
initLogin logtest = new initLogin();
uName = "david";
pWord = "rachel";
validtst = logtest.authenticate(uName, pWord);
System.out.println(validtst);
if (validtst){
pmuser = "true";
}
else if (!validtst){
pmuser = "false";
}
return pmuser;
}


and this is initLogin class:


public class initLogin {


private String username = "";
private String password = "";


public initLogin() {
}


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 USERS;";
String DbUserName="";
String DbPassword="";
String finalUser="";
String retval = null;


String data = "jdbc:eek:dbc:GADXML";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(data, "system",
"rosetta");
Statement stat = conn.createStatement();
ResultSet rst=stat.executeQuery(query);
StringBuffer testUser = new StringBuffer(username2);
StringBuffer testPass = new StringBuffer(password2);
String testuser = testUser.toString();
String testpass = testPass.toString();


parameterInput chkparm = new parameterInput();
retval = chkparm.readLine(testuser);
username2 = retval;
retval = null;
retval = chkparm.readLine(testpass);
password2 = retval;
retval = null;
System.out.println("username -- " + username2);
System.out.println("password -- " + password2);
while(rst.next())
{
DbUserName=rst.getString("username");
DbPassword=rst.getString("password");
finalUser=rst.getString("usertype");
finalUser=rst.getString("approver");
testUser = new StringBuffer(DbUserName);
testPass = new StringBuffer(DbPassword);
testuser = testUser.toString();
testpass = testPass.toString();


retval = chkparm.readLine(testuser);
DbUserName = retval;
retval = null;
retval = chkparm.readLine(testpass);
DbPassword = retval;
retval = null;
if (username2.equals(DbUserName) &&
password2.equals(DbPassword)) {
return true;
}
}
return true;
}
catch(Exception e){
e.printStackTrace();
System.out.println("here is the problem -- " + DbUserName);
return false;
}
}
}


And parameter input:


public class parameterInput {
String input = null;
public static String readLine(String firstVal){
StringBuffer response = new StringBuffer();
try {
System.out.println("passed value -- " + firstVal);
StringReader buff = new StringReader(firstVal);
int in = 0;
int totval = 0;
int inplace = 0;
int nextplace = 0;
char inChar;
do {
in = buff.read();
inChar = (char) in;
if ((in != -1) && ((inChar != '\n')||(inChar !=
'\t'))){
response.append(inChar);
inplace++;
nextplace = inplace + in;
totval = totval + nextplace;
System.out.println("char: " + inChar + " value: " +

in );
}
} while ((in != -1) & ((inChar != '\n') || (inChar !=
'\t')));
buff.close();
return response.toString();
// return totval;
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
return null;
}
}
}


Here is the TestGad class:


public class testgad {
private String valid = "";
private String passWord = "";
// public static int username = 0;
// public static int password = 0;
public static String username = null;
public static String password = null;
boolean truetest = false;


public testgad() {


System.out.println("newtest");
initLogin logtest = new initLogin();
System.out.println(username);
System.out.println(password);
truetest = logtest.authenticate(username, password);
if (truetest){
System.out.println("its true");
}
if (!truetest){
System.out.println("its not really true");
}


// loginbean logtest = new loginbean();
// logtest.authent2cate(username, password);
}


public static void main(String[] args) {
username = "david";
password = "rachel";
testgad testgad = new testgad();
}
}


This code basically cycles through the oracle user database and
compares passwords for login to either the web, via the loginserverlet
class or from the console using TestGad class. TestGad works fine but
loginserverlet does not. It consistently returns "false" which is not
correct. both classes are "hardcoded with a username and password" so
the results should be the same. Thank you for your response.

N-.

Reply »
 
L

Lew

N-. said:
PROBLEM SOLVED!!! THANKS!

We'd be interested in knowing how.

Also, please post responses inline, not at the top.

By convention nearly as old as the Java language, one should spell class (and
interface) names with an initial upper-case letter, and capitalize the first
letter of each "word part" within the class name ("camel case"), e.g.,

public class LoginServerlet ...

By contrast, method, variable and instance names should begin with a
lower-case letter and capitalize the first letter of subsequent word parts, as
you did with "userName" but not "parmuser".

You can download direct JDBC drivers from Oracle for free. The JDBC-ODBC
bridge will lack performance and flexibility compared to the Oracle drivers.

- Lew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top