Is storing answers to security questions in plain text bad form?

I'll assume the model you're trying to defend against is where an attacker has access to the database. If that's the case, yes, it's a bad idea if an attacker can compromise an account by only knowing those details.

My advice would be to convert the answer to uppercase, then salt + hash it. Optionally also trim it or collapse all whitespace. This provides a reasonable security measure without reducing usability.


If those questions provide the same level of access as the password, then for all practical purposes they are a password and should be treated like one. Apply the same level of protection to all passwords that you store.


The answer is yes, you should always hash this.

Why do we hash stuff like passwords at all? Two reasons: mainly because people often use the same password for many different things, and additionally (it's more of a fortunate side-effect) to prevent attackers from logging in when they obtained read-only database access.

So don't you think the user's first pet or mother's maiden name is also data that he would use across multiple services? Or that could potentially be used for social engineering attacks? Or could be used to reset the password and also gain access?

For that reason, you should protect answers to security questions against attackers (and admins!) the same way as you do with passwords.

Why not encrypt it?

Encryption is reversible, it makes it possible to access the data while there is no need to. One of the cases you're trying to prevent by protecting the database data, is a case where the server is compromised, or where an insider has bad intentions. In both cases, they could use the decryption key to reverse the protection. With decent hashing, this is no longer possible.

But what about punctuation? You can't match a hash unless it's exact.

People might use multiple words in an answer, and one time they might use capitalization, other times they might remove spaces between words or put a period behind the sentence... so I'd suggest normalizing it to at least remove spaces, remove punctuation and lowercase any capital letters.

Regardless of whether you have it stored plaintext or encrypted, you need to write a normalisation algorithm to compare them anyway (so that does things like lowercasing). That algorithm will boil it down to a basic version to be able to decide whether it a match. If you apply that before hashing the result, it will work just the same.

PS. Don't do security questions. They're super bad for a lot of reasons. But if you do use them, then at least protect your users a little bit and hash the answers.