5

Java's JPasswordField is encoding the input which user enter in password field and I don't want it. I am checking password against database values which are purely numeric values.

Am entering the numeric values for password as

12345 

and it returns

[C@1e9b48b
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

2 Answers2

4

I think when you mean encoding, you're probably trying to use the toString method. Which on a char array, will just use the standard object toString method.

Instead you could probably do

String password = new String(passwordField.getPassword());

The only other way it's "encoded" is if you're getting an encrypted password somehow.

Austin
  • 4,801
  • 6
  • 34
  • 54
  • +1, though note that passwords are typically not returned as `String` instances for very a good security related reason. I am not sure what that reason is, but it has probably been asked/answered many times before. – Andrew Thompson Oct 15 '12 at 06:15
  • @user1734885 If it worked, you're welcome to press the checkmark button to mark the answer as accepted :) – Austin Oct 15 '12 at 06:16
  • 1
    Converting the `char[]` to a `String` is of course an answer to this question, but it is not the recommended way for dealing with passwords. See [this answer](http://stackoverflow.com/a/9798093/1076463) on a related question – Robin Oct 15 '12 at 06:18
  • 2
    @AndrewThompson The reason is so that you can null out the array after use. You can't do that with a String so it remains lying around, readable from e.g. the swap file. – user207421 Oct 15 '12 at 06:28
-1

The doc come with a sample http://docs.oracle.com/javase/tutorial/uiswing/components/passwordfield.html

The input is not 'encoded' but for each character you enter a special character is printed in the inout field.

Timo Hahn
  • 2,466
  • 2
  • 19
  • 16