5 Replies - 2323 Views - Last Post: 19 April 2011 - 04:15 PM Rate Topic: -----

#1 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

JPasswordFild and .getPassword() method

Posted 19 April 2011 - 03:01 PM

Hello,
when I write some text into the JPasswordField and call .getPassword() method on it, it returns that text hashed(?). For example, when I write "qwerty" into JPasswordField, .getPassword() returns [C@3bbe9a50.
Any idea which hash algorithm it uses? I wasn't able to find it in a documentation. I know, that I can use .getText() and than use my own hash algorithm, but .getText() is deprecated and .getPassword() recommended instead it.

This post has been edited by Dworza: 19 April 2011 - 03:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: JPasswordFild and .getPassword() method

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,537
  • Joined: 27-December 08

Re: JPasswordFild and .getPassword() method

Posted 19 April 2011 - 03:12 PM

The getPassword() method returns a char[]. You are probably printing that array directly, rather than creating a String from it. As arrays do not override the Object toString() method, you are getting the memory location. Note that you can create a String by passing a char[] to the constructor.
Was This Post Helpful? 1
  • +
  • -

#3 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

Re: JPasswordFild and .getPassword() method

Posted 19 April 2011 - 03:18 PM

nope, this shouldn't be that problem.

char[] password = LoginFrame.pass.getPassword(); //get user password
pass = password.toString();
System.out.println(pass + " PASSWORD");



when I use this, then the output looks similar to that, what I've posted...


pass = LoginFrame.pass.getText(); //get user password
System.out.println(pass + " PASSWORD");



but when I use this code, it returns correct output

This post has been edited by Dworza: 19 April 2011 - 03:20 PM

Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,537
  • Joined: 27-December 08

Re: JPasswordFild and .getPassword() method

Posted 19 April 2011 - 03:22 PM

Exactly as I said before- you are using the toString() method which return the memory address. You need to instantiate a new String:
String s = new String(myCharArray);
System.out.println(s);


Was This Post Helpful? 0
  • +
  • -

#5 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

Re: JPasswordFild and .getPassword() method

Posted 19 April 2011 - 03:29 PM

Uh..you're right... I'll go somewhere into a corner and I'll be ashamed there... Thanks for help :)
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,537
  • Joined: 27-December 08

Re: JPasswordFild and .getPassword() method

Posted 19 April 2011 - 04:15 PM

Glad I could help! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1