JPasswordField: getPassword return type

O

obhiee

Possibly OT, but I'm curious.
Why does getPassword return a char[] when getText returned a String?

It seems odd that the older method returned a String object while the
newer method returns a an array of char.

regards,
Abhishek.
 
D

ddimitrov

Check the javadoc:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JPasswordField.html#getPassword()

Since in Java the strings are immutable, there is a chance that the
password will stick in the heap for a long time. Thus, it's considered
safer to use the array representation of the password to calculate a
hash and then zero out the array's contents.

If you are not that concerned with security, you can keep using the
getText() or convert the pass to String and use it as plain text.

Dimitar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top