Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String Validation Issues  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please print the two passwords you compare in the validatePassword() method before the line #5.
 
Ranch Hand
Posts: 75
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes... thanks for correcting it..
 
Mark Captain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!
 
BWA HA HA HA HA HA HA! Tiny ad:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!