Stack Overflow archive
2 score

Reading passwords with System.console()

score
2
question views
1.4K
license
CC BY-SA 3.0

This question reminds me of the discussion in this popular answer from Why is char[] preferred over String for passwords?

As noted in comments, it's possible that arrays being moved by the garbage collector will leave stray copies of the data in memory. I believe this is implementation-specific - the GC may clear all memory as it goes, to avoid this sort of thing. Even if it does, there's still the time during which the char[] contains the actual characters as an attack window.

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.