This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String Validation Issues Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "String Validation Issues" Watch "String Validation Issues" New topic
Author

String Validation Issues

Mark Captain
Ranch Hand

Joined: Nov 01, 2011
Posts: 30
Hello, in my program I am trying to validate if a password is correct. However I am coming up with the problem of the code saying the password is incorrect even when it is correct. it looks as it is not comparing the newly inputted password but it is using the one declared in the driver. Any ideas?

The two strings i am trying to compare are the users input password, and the saved password. The are declared in the main driver like so


The method is called in the driver



The readPassword method


and the validation method
John Jai
Bartender

Joined: May 31, 2011
Posts: 1778
Please print the two passwords you compare in the validatePassword() method before the line #5.
Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 65

Hi Mark,

First off, I see that even if your readPassword method is returning the typed password, you are not using it in the driver, here:

I guess it would be better if you had:


Secondly, when calling the validatePassword method, you may have accidentally sent the first two parameters, password and PASSWORD in the incorrect order.

Cheers,
Claudiu
Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 65

John Jai wrote:Please print the two passwords you compare in the readPassword() method before the line #5.


I think you meant the validatePassword() method, right ?

Claudiu
John Jai
Bartender

Joined: May 31, 2011
Posts: 1778
Yes... thanks for correcting it..
Mark Captain
Ranch Hand

Joined: Nov 01, 2011
Posts: 30
Claudiu Chelemen wrote:Hi Mark,

First off, I see that even if your readPassword method is returning the typed password, you are not using it in the driver, here:

I guess it would be better if you had:


Secondly, when calling the validatePassword method, you may have accidentally sent the first two parameters, password and PASSWORD in the incorrect order.

Cheers,
Claudiu


Thank you, this solved my problem!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: String Validation Issues
 
Similar Threads
This may be easy
Multiple errors - Choose both?
JayBird / Firebird nullpointerexception when using getInt()
How to compare two StringBuffer or StringBuilder objects ?
Login Servlet