Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passwords not matching read using Console

 
Raman Ghai
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there ,
I have created a program that stores and authenticates a user using a file .
Here is the code :


The passwords don't match even if I enter same passwords . How to solve this problem ?
Whenever a new user enters , the data overwrites the previous contents of the file , how to append ?
Can I use regex to compare here ? Any ideas will be appreciated ..thanks
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You twice made the assumption that a char[] is the same thing as a String. Its not:

In your store method you have the equivalent of:

You expect it to do create "my name:abc" but it won't, because char[] is not a String.

Second, in your verify method you have the equivalent of:

You expect that this would return true. But since a char[] is not the same as a String and so could never be equal.
 
Raman Ghai
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You twice made the assumption that a char[] is the same thing as a String. Its not:

Just to confirm

Output : false
Well , I need to find some other way out. Btw thanks for replying
 
Paul Clapham
Sheriff
Posts: 21298
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there's a String constructor which accepts a char array, isn't there?
 
Raman Ghai
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Well, there's a String constructor which accepts a char array, isn't there?

Yes, there is


//Calls

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic