I'm trying to determine the best way to implement password validation in Java. The password is stored as text in an SQL database.
Should I:
- Query for password based on user name and validate it within Java app? (SELECT password FROM users WHERE username = 'foo')
- Query for row based on user name + password input? (SELECT true FROM users WHERE username='foo' and password='bar')
- Something else entirely...
If the answer is #1, what is the correct way to get the password hash into Java? I know that passwords should be stored as a char[] instead of a String to avoid leaving a copy in memory, but is it ok to retrieve it from the result set using ResultSet.getString("password")? Wouldn't that create a String constant and be a security risk (even if hashed)? The other option I see would be to store/convert the password to an array within SQL and then use ResultSet.getArray() to retrieve it, but that seems a little excessive unless absolutely necessary.
Edit:
Ok, maybe I made a mistake by using the word TEXT in the same post as PASSWORD, but I was referring to the data type, not saying that I'm saving the passwords in plain-text. In fact, I clearly asked "what is the correct way to get the password hash into Java". Please stick to the question that I asked if you want to be helpful.