5 ms·
For the people not understanding why this discussion is a problem, in synopsis: In order for a server to use encrypted passwords for authentication, the server
by Alupis 12y ago
For the people not understanding why this discussion is a problem, in synopsis:
In order for a server to use encrypted passwords for authentication, the server must have access to the decryption key -- which means an attacker has access to your decryption key if they can compromise your box. Furthermore, if they don't get your decryption key, but they get your database dump -- they can then just brute your db and decrypt the passwords. They can do this because encryption is, by design, reversible. Encrypting passwords is almost as bad as storing in plain text.
Cryptographically hashing a password is the only way to go. When you cryptographically hash a password, using a known library that has been tested and written by actual cryptographers with passwords/authentication in mind (like bcrypt, etc -- no, sha's and md5's are not safe to use) - you get a one-direction algorithm in that a password goes in, is digested, and a fixed-length hash output comes out. There is no way to reverse this hash back into the original input. Adding salt(s) combats people making rainbow tables against your implementation, as they then would need to know not only which algorithm you are using, how many iterations it does, but also what your salt(s) are (sometimes even varied every so many iterations). This makes it almost impossible for someone to brute your leaked password database.
- sarciszewski 12y agoThank you for posting this. +1
- aerovistae 12y agoI was under the impression SHA256 is valid...it's a cryptographic hash function that hasn't had weaknesses identified yet. 40 iterations of that + salting would suffice, no?
- aerovistae 12y agoI do realize bcrypt is arguably the best option, but why is SHA not valid also?
- tptacek 12y agoBecause it has no work factor. It's uniformly fast, which makes it very easy to brute force. The general-purpose strong cryptographic hashes --- your SHA2s, SHA3s, and BLAKE2s --- are all amenable to fast implementation on GPU. What you need is a password hash, not merely a cryptographic hash.
- aerovistae 12y agoAs noted above, this discussion prompted me to investigate my company's methods, a fairly major US website, and I found they're using SHA-256 for 50 iterations with salting. Does that slow things down sufficiently, or is that not comparable to the internal mechanism of bcrypt?
- sarciszewski 12y agoNo. Currently, PBKDF2 (which iterates HMAC-SHA1, HMAC-SHA256, etc.) typically is used with a count in the thousands. I'd recommend upgrading to follow best standards. If you use PHP, scrypt isn't that hard to set up. https://scott.arciszewski.me/blog/2013/10/php-scrypt-setup https://scott.arciszewski.me/blog/2013/10/php-scrypt-setup
- aerovistae 12y agoCompany is stuck with ASP.
- sarciszewski 12y agohttp://www.dotnetnoob.com/2012/05/towards-more-secure-password-hashing-in.html http://www.dotnetnoob.com/2012/05/towards-more-secure-passwo...
- aerovistae 12y agoThank you!
- danielweber 12y agoIf you change 50 to (say) 1000 you are getting most of the benefits. The big problem you are trying to solve is "our password database just leaked; how fast can attackers figure out the passwords?" Say you can run SHA in 1 microsecond, and 1000 iterations in 1 millisecond. Even though it's 1000x slower, that's probably an unnoticeable difference as far as your performance is concerned. (YMMV) But, anyone trying to brute-force the passwords out of your database will now have to do 1000x the work. BTW, none of this will help you much if your users choose passwords like "abc" or "password". (IIRC scrypt lets you blow up in size as well as CPU, which makes GPUs impractical for attacking.)
- Alupis 12y agothe SHA algorithms were designed to digest data as fast as possible -- which things like bcrypt purposefully slow it down plus can perform multiple iterations with the output of one iteration feeding as the input to another. Here is some more info: http://forums.udacity.com/questions/6016855/hashing-passwords-using-sha256-is-not-enough-today http://forums.udacity.com/questions/6016855/hashing-password...
- sarciszewski 12y agoIf you're going to use SHA256 for hashing, why not use it in PBKDF2-SHA256? https://defuse.ca/php-pbkdf2.htm https://defuse.ca/php-pbkdf2.htm
- Sir_Cmpwn 12y agoTo expand upon that... The problem with md5 and sha and such is that they are fast. bcrypt is useful because it takes a fixed amount of complexity which can be specified by the programmer (and later increased). It also uses salts to thwart rainbow tables. The complexity bit is important, though, because as computers get better, you can make it harder to reverse your passwords. Also, the biggest reason any of this is a problem is because password reuse is rampant. You are being entrusted with the password to your user's life - their email, their bank account, their facebook account... treat it with respect.
- tptacek 12y agoThis summary created more questions than it eliminated. Nobody has explained this better than Coda Hale: http://codahale.com/how-to-safely-store-a-password/ http://codahale.com/how-to-safely-store-a-password/ (in place of "bcrypt", you can substitute "PBKDF2" [weaker] or "scrypt" [stronger], but all those options are just fine).
- aerovistae 12y agoI'm a bit confused. This article says SHA-256 is a general purpose hash algorithm, but wikipedia says it's a cryptographic hash function. Is the wiki article wrong?
- sarciszewski 12y agoIt's a cryptographic hash function for general cryptographic usage (e.g. HMAC), but it's not a password hash function.
- owenmarshall 12y agoBoth are correct. A cryptographic hash function is a hash function that is not invertible, resists tampering and collisions, and has other properties. Using cryptographic hash functions in certain cryptographic settings is appropriate. SHA256("My Super Secret Password") is not one of those settings. SHA256 can be the basis of a scheme to securely store passwords. There are many different names for that: * key derivation function * secure password storage scheme * password scrambler (PHK's term) * (...) A secure password storage scheme uses a cryptographic primitive like a cryptographic hash or a cipher to increase the time it takes to decrypt passwords. That's a good thing, because when it takes your user 0.5 seconds to go from "right password -> on disk hash", it'll take a prohibitively long time for an attacker to guess through passwords.
- aerovistae 12y agoOkay, that makes sense. SHA-256 for 50 iterations, with salting: is that equivalent to bcrypt in the matter of slowing things down....is it good enough?
- pinkyand 12y agoTrue, that's the tech behind it. Is there any reason most programmers should know any of this ? The code should look more like this(and should use a standard library): import Password_protector P = Password_protector(date_of_first_use) #library upgrades algorithms every once in a while, only a single algorithm available per date. If there's a need for automatically upgraded hashing library should handle covertly. protected_password = P.protect_password(password) if P.compare_password(password, protected_password) == True ... Or something similar. That at least should cover the basics - safely.
- mikeash 12y agoQuite simply, the reason programmers should know about this (if they're implementing a password system) is because the library you propose often doesn't exist, and when it does exist it's often implemented incorrectly. In an ideal world, programmers shouldn't have to worry about this stuff. But this is not an ideal world.
- sarciszewski 12y agoI suppose that's Python? The whitespace got chewed up by the comment system; please pastebin/gist it instead.
- deleted 12y ago[deleted]