aspose file tools*
The moose likes Servlets and the fly likes Login code problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Login code problem" Watch "Login code problem" New topic
Author

Login code problem

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Login code problem , whenever i input crrect login details it is not displaying Login successful




http://www.lifesbizzare.blogspot.com || OCJP:81%
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


You are not helping yourself writing code like this. The exception will include a stack trace that is full of helpful detail.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

Line number 51 ->

why dont you try using "equals" String Equals


Time is what we want the most, but what we use the worst. -- William Penn
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Robin John wrote:Line number 51 ->

why dont you try using "equals" String Equals



Hi Robiin I used .equals(Data_Id) still same problem its showing me a blank page instead of displaying login successful
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

When i changed the if loop it worked?? but it makes no sense??

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 556

You are closing the printwriter out on line 75. Just comment that line, it should work for you..
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

hmm interesting... did it work ?

closing the stream is a good practice... use flush before closing... Check Here

and I dont understand why do many use != and == for string operations even if it works sometimes (does it ?)....

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Hi Robin,

Nope it didnt work ..I also tried String1.equals(string2) still same problem.. I am not understanding where i am going wrong?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
Since you have made several changes to the code at this point, you should edit the first post with the code that you are now trying and which is still failing.


Ping & DNS - my free Android networking tools app
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Hi Ulf,

Edited the Code post
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
That code still uses the equality operator ("==") to compare strings. As was pointed out before, that is simply wrong.

Also be aware that the JDBC/ODBC bridge is not thread-safe, and that the code is vulnerable to SQL injection attacks.
Larry Chung
Ranch Hand

Joined: Feb 02, 2010
Posts: 247
Vishal Hegde wrote:When i changed the if loop it worked?? but it makes no sense??



Vishal, of course (U_Name!=Data_Id && Passwd!=Dat_Passwd) will produce "Login Successful" because your ResultSet data very likely has instances when usernames and passwords do not match the entered username and password in the Request. Therefore the boolean logic in the "if" statement will be TRUE. What is the data in your Customer data table? For troubleshooting the problem, I suggest you change the "else" block to:

Then tell us what is your output.


SCJP 6
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055



Remade the code and still the same problem


Hi Larrry I inputted the variables in the else loop the values being displayed are correct.....I dont know why it is going to the else loop

Heres the simple login html page i used


Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Larry Chung wrote:
Vishal Hegde wrote:When i changed the if loop it worked?? but it makes no sense??



Vishal, of course (U_Name!=Data_Id && Passwd!=Dat_Passwd) will produce "Login Successful" because your ResultSet data very likely has instances when usernames and passwords do not match the entered username and password in the Request. Therefore the boolean logic in the "if" statement will be TRUE. What is the data in your Customer data table? For troubleshooting the problem, I suggest you change the "else" block to:

Then tell us what is your output.



Hi Larry despite inputting the same login id and password as inputted in database still the code is flowing in the else loop
Larry Chung
Ranch Hand

Joined: Feb 02, 2010
Posts: 247
Vishal, please show me the output.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
Make sure the DB query returns what you think it should return.
Rahul Manikuntla
Greenhorn

Joined: Apr 07, 2010
Posts: 11
So Vishal, what did you find out about the cause of the problem?


SCJP 5.0
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Rahul Manikuntla wrote:So Vishal, what did you find out about the cause of the problem?


Hi Rahul,

I still havent traced the root cause of the problem

Will sure update in this post once my problem is resolved
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Larry Chung wrote:Vishal, please show me the output.


Database is like this

User_Name Password_Name


tiwarish demo@345

Also output is getting the same
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

when i tried printing objec1.equals(Object2) it returned false. Should i try overridinng hashcode() or equals() method???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
Vishal Hegde wrote:Database is like this

User_Name Password_Name

tiwarish demo@345

Just to make sure: These two values are what is returned by the query? Note that I'm specifically not asking what is in the database - I'm asking whether that's returned by the query.

Should i try overridinng hashcode() or equals() method???

No.

I'd say the question is which of the 4 values in question is different from what you expect it to be. You should log them all if you haven't done so yet, so that you can check what their actual values are.

As another aside, the last code you posted is still vulnerable to SQL injections attacks. This is simply not acceptable, and you must fix it. The easiest way is to use a PreparedStatement. There are several other aspects in the code that should get fixed, but that's by far the most important one.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Hi Ulf,

I am confident that you know what is the actual logical error , please let me know I have been struggling since afternoon...I promise alongwith time my programming logic will improvise
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
You'll learn much faster by trying things yourself. Debugging is an important skill for a developer to have, starting with simple things like the logging of relevant variable values.

PreparedStatement, on the other hand, is explained in its javadocs and in the JDBC trail of the Oracle Java Tutorial.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Yay It worked trim() helped me out..

Thanks Ulf for making me aware of SQL Injection
mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 244

Is your problem solved ?

May be it may help's you try it

Remove the quoted one

Vishal Hegde wrote:



Add the fallowing code


Use prepared statement it will be so easy
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

mallikarjun don wrote:Is your problem solved ?

May be it may help's you try it

Remove the quoted one

Vishal Hegde wrote:



Add the fallowing code


Use prepared statement it will be so easy



Hi Mallikarjun,


Yes the problem is resolved i used the trim() function when retrieving data from the database and it resolved the problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Login code problem