Sorry to bring this topic up again, I have carefully read another similar question Why does JPasswordField.getPassword() create a String with the password in it?
However I still think there is a loophole in JpasswordField implementation. I still see password being stored in Memory maybe in different data types, not String.
Step that I did: Download the JPasswordField Demo code from Oracle https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/components/PasswordDemoProject/src/components/PasswordDemo.java
and run it. It will bring up the password dialog.
Type in "bugaboo"
Hit enter and see that password is correct. (I delete the typed in password, the end result is the same with/without this delete)
Now at this point, due to the code to clear password content in
//Zero out the password.
Arrays.fill(correctPassword,'0');
I expect there is no leftover bugaboo in memory, however there is.
I used http://www.sweetscape.com/010editor/ to examine the memory content and still see "bugaboo" in clear text
Conclusion: the reason for this is that JpasswordField internally use PlainDocument and it litter your memory with the whole history of what was keyed in. Hence you cannot fully clear the password clear text in memory.
Therefore the effort to use getPassword() as char[] and clear it afterwards doesn't have much benefit.
Please enlighten me.