After reading this beautiful question: Why is char[] preferred over String for passwords?, I'm curious as to how this applies to servlet based web applications. Say your UI has some input field for the password, the password will be retrievable with request.getParameter("passwordFieldName")
which returns a String
. Even if you then convert it to a char[]
, you have to wait for GC to clear the String
object.
Also, many of the Encryption/Hashing libraries I'm looking into using for password hashing have a method such as checkPassword(plaintext, hashed)
that takes two Strings and returns true if the entered plain text string gives a hash equal to hashed
. With this, even if you had a char[]
, you would still need to convert the array to a String with the new String(char[])
constructor.
It seems to me like you can't really avoid having your password as a String for comparing it to its stored representation. If you are worried about attacks during that small window, how do you protect yourself?