by ehsanul · 16y ago · 0 comments
In addition, bcrypt() allows you to increase the amount of work required to hash a password as computers get faster. Old passwords will still work fine, but new passwords can keep up with the times.
Obviously, old passwords would be weaker than new passwords this way. An easy solution to this problem is to check the cost of hashed password in your database when a user tries to log in. If the cost is lower than the cost you want, and the password matches, then replace the hash at higher cost using the password the user just gave you.
As for hashing SSNs, you can easily overcome the problem of a limited range of data by the usual solution: salting. Bcrypt-ruby does salting automatically, which you can observe by rehashing a password in irb multiple times, getting different results (the salt is also stored with the hash, which makes this possible). You can also add additional salt yourself if you really want to.
Here's another idea: Use a secret salt, similar to AWS's secret id. Make it long enough that it would pretty much impossible to brute-force (do the calculations). Does that seem like a workable solution? Of course, if the "secret" isn't secure, then well, you're in trouble, and if the secret is in your code in plaintext... Yeah, it's an uphill battle. I'm sure someone more experienced than me here can provide some solution.