• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Login code problem

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Login code problem , whenever i input crrect login details it is not displaying Login successful


 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You are not helping yourself writing code like this. The exception will include a stack trace that is full of helpful detail.
 
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line number 51 ->

why dont you try using "equals" String Equals
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i changed the if loop it worked?? but it makes no sense??

 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are closing the printwriter out on line 75. Just comment that line, it should work for you..
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Robin,

Nope it didnt work ..I also tried String1.equals(string2) still same problem.. I am not understanding where i am going wrong?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Edited the Code post
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vishal, please show me the output.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure the DB query returns what you think it should return.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So Vishal, what did you find out about the cause of the problem?
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i tried printing objec1.equals(Object2) it returned false. Should i try overridinng hashcode() or equals() method???
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yay It worked trim() helped me out..

Thanks Ulf for making me aware of SQL Injection
 
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
What's a year in metric? Do you know this metric stuff tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic