6 ms·
I've asked these questions in interviews and a lot of programmers seem to know the basics (what a hash is), but seem to fall short when it comes to things like
by rcconf 10y ago
I've asked these questions in interviews and a lot of programmers seem to know the basics (what a hash is), but seem to fall short when it comes to things like what a salt is, modern storage techniques (bcrypt, scrypt, PBKDF2) and how rainbow attacks can be used to crack hashes.
It's a bit tricky to fail someone in an interview because they don't know security. I think the better way to handle security in a company is to hire a programmer that knows it and teaches it to other programmers during code reviews.
- t3nary 10y agoHashing with an insecure algorithm and without good salting isn't much better that not hashing at all though.
- dzhiurgis 10y agoHow do you store salt?
- CiPHPerCoder 10y agoThat question should never even need to be asked. The library you're using should take care of that for you. In PHP: $storeMe = password_hash($plaintext, PASSWORD_DEFAULT); if (password_verify($plaintext, $storeMe)) { // Logged in } The detail is totally abstracted away. All sane password hashing libraries offer this API. See: https://paragonie.com/blog/2016/02/how-safely-store-password-in-2016 https://paragonie.com/blog/2016/02/how-safely-store-password... EDIT - CANNOT REPLY: > One major failure of this article: > > You should generate a random salt for each user and store it alongside the user > record in the DB. No, you shouldn't. Your library should do that for you, and store it as a single string that's opaque to the developer. > I completely disagree. This implies that my DB ORM handles password stuff, > which doesn't make sense. See the passlib section: https://paragonie.com/blog/2016/02/how-safely-store-password-in-2016#python https://paragonie.com/blog/2016/02/how-safely-store-password...
- tamana 10y agoBut then you are using php so you already lost.
- CiPHPerCoder 10y agoIf there was any truth at all in that claim, you should be able to compromise paragonie.com right now simply for it running PHP. Otherwise, that claim is false.
- jjawssd 10y agoOne major failure of this article: You should generate a random salt for each user and store it alongside the user record in the DB.
- dchest 10y agoHow is this a failure? That's correct. (If your password hashing library doesn't handle this automatically, of course. But it does the same internally.)
- jjawssd 10y agoIs it normal for password hashing libraries to save salts to a database?
- dchest 10y agoYes, they usually produce a string that looks something like "salt||hash". (Salt is a non-secret value.) This result of bcrypt: $2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy |/ \| \____________________/\_____________________________/ | | salt hash | cost | algorithm, version You store this string in the database.
- zo1 10y agoThe big thing about this, is that it is perfectly "OK" to store both the algorithm, cost, and salt alongside the hash. Most people seem to think, and myself included when I was new-to-it, that storing all those things together would compromise the security. The point of the hash is that it is impossible (almost) to get to the hash without the user's password, and there is no way to get to the password with the entire string you posted.
- dchest 10y agoNope, it is much better for those who use passwords with good entropy.
- staticelf 10y agoCryptography is hard and best practice should be to use common libraries to help you get it right.
- cm2187 10y agoIt's not about writing your own crypto. It's about knowing not to use the md5 library but the bcrypt library instead.
- tamana 10y agoIdeally the md5 library documentation says "this is a digest function, not a secure bash"
- geocar 10y agoThose words might as well be in greek. How about: You should use the md5 function to produce a string you can compare with the md5 function. md5 is obsolete, does not offer much security, and should not be used in new programs except for the purposes of interoperating with old programs, and even in that case, one should weigh the risks of interoperation with the costs of replacing. If you are looking for a suitable replacement for md5, you should instead be looking for specific use-cases, such as content verification (links...), authenticated content verification (links...), password verification (links...), random number generation (links...), shared secret encryption (links...)
- cm2187 10y agoIn fact you only want to use it when your comparison can afford collisions (md5 generates a lot of collisions). Sha256 is pretty much collision free.
- golergka 10y agoPersonally, I think it's quite enough if a programmer at least knows that he doesn't know certain aspects of security — and instead of importing standard library's md5 module, spends at least 20 minutes on Google when faced with such a task.
- MOARDONGZPLZ 10y agoIs there a good article or breakdown on modern best security practices? I am a relatively experienced programmer and know what a hash and salt are, and have read the wikipedia article on rainbow tables (though I now forget what they are other than that they make attacks of certain things easier), but that's the extent of my knowledge.
- CiPHPerCoder 10y agoHere's one. Title: How to safely store your users' passwords in 2016. https://paragonie.com/blog/2016/02/how-safely-store-password-in-2016 https://paragonie.com/blog/2016/02/how-safely-store-password...
- jtchang 10y agoThat site recommends libsodium which by default uses Argon2. The issue is that Argon2 is not very mature yet. Also if you are using python there is no good library out there. Ideally you want something well tested since it is possible for libraries to have bugs as well.
- barsonme 10y agoThere's this good link from Thomas Ptacek: https://gist.github.com/tqbf/be58d2d39690c3b366ad https://gist.github.com/tqbf/be58d2d39690c3b366ad
- zo1 10y agoThe best one I've come across is actually an answer on the Security StackExchange. http://security.stackexchange.com/questions/211/how-to-securely-hash-passwords http://security.stackexchange.com/questions/211/how-to-secur...
- Royalaid 10y agoThe best resource I have found is https://www.owasp.org/index.php/Main_Page https://www.owasp.org/index.php/Main_Page