14 ms·
How To Safely Store A Password
- asdfor 16y agoIts really simple , AS LONG AS the user uses a weak password, using bcrypt or not wont protect him. Why ? Well instead of brute forcing the hashed password i'll directly try to bruteforce using the normal login method of your site (even if you rate limit my login attempts it wont take that much time...(see proxys)(if you are thinking about rate limiting per username etc you suck). If you need yours users account to be safe just force them to use a strong enough password hashed(password + salt) = epic win
- davebob 16y agoplease explain what you mean by rate limiting and why that's no good.
- asdfor 16y agoIn some period of time a user is only able to do some amount of login attempts, after that he has to wait until he can try again to login. You can do that per IP or per username, doing it per username its not good because someone can abuse that to block the genuine user to log in. Doing it per ip is the best option you have and i didn't say that its not good, what i said is that if the user uses a weak password even if you put a rate limit they will be able to find the password soon enough.
- Raphael 16y agoI think rate limiting per user is perfect. And if the real person wants to log in while someone else used up their attempts, do a quick email confirmation.
- asdfor 16y ago"do a quick email confirmation". And what happens if one or more of your users gets targeted for a long period of time ? You will force them to open there inbox every time they want to log in your site ? And this gets even better if they target your site generaly, it will be a lot of fun for the majority of your userbase to have to do that "open inbox" step, bet users will love it :) Sorry mate but your method sounds easily exploitable ... heck using reCaptcha would be less punishing for the user than your approach.
- jimwise 16y agoI'm not so sure. The other side of the coin is that ``{MD5, SHA1, SHA256, SHA512, SHA-3, etc}'' have had extensive peer review in the cryptography world. There's a long history of ``clever new ways'' to use existing crypto algorithms turning out to have serious flaws -- a good example is early attempts to improve the strength of (56-bit key) DES by encrypting three times with three keys. This turns out to introduce enough non-randomness to make the result much weaker than one might expect; standard 3DES works by encrypting with the first key, decrypting with the second, and encrypting with the third, which results in very different properties of the output cyphertext. I'm not saying BCrypt has the same sort of issues, but I'd like to see some cryptanalysis of this before trusting my users' data with it. Notably, there seems to be no links to such analysis on the BCrypt home page -- not even an argument from the author as to why this code should be cryptographically sound.
- Xk 16y agoNo. Use Bcrypt. Always. Bcrypt is backed by Blowfish, designed by Bruce Schneier. Go look it/him up. It's secure. MD5/SHA1/etc are not weak because they are cryptographically weak (though some are), it is weak because they are fast. SHA3, when it is picked, will still be a very bad choice because it too will be fast. So, why Bcrypt? Well, it uses Blowfish. Blowfish has a very slow key scheduling algorithm which basically involves a lot of hashing to get the round subkeys. Bcrypt makes this even slower. So what? Well, with Bcrypt you could set it up to take .3 seconds to verify a password. Try bruteforcing on that.
- ax0n 16y agoIndeed. Blowfish is also standardized and has withstood peer review, cryptanalysis and has otherwise been baptized by fire. Plus, if it's good enough for people as picky as Theo DeRaadt, it's probably good enough for you.
- jimwise 16y agoThe question is not whether BCrypt is backed by Blowfish, the question is whether BCrypt uses Blowfish in a way which is cryptographically sound. If it does not, then an attacker may not need to use brute force. Assuming the author has read more of Mr. Schneier's book than the quoted preamble, he should know this -- Schneier discusses this at length in both editions of Applied Cryptography. Again, an example of this is the 3DES encrypt/decrypt/encrypt process vs. a more naive encrypt/encrypt/encrypt process. One is substantially stronger than the other. One is a secure way to use DES, and one is not.
- tocomment 16y agoHN, is this the consensus? I thought certain hashes worked fine when properly salted?
- deleted 16y ago[deleted]
- frisco 16y agoYes, this is consensus. "Salting" isn't actually a real security practice. See: http://chargen.matasano.com/chargen/2007/9/7/enough-with-the-rainbow-tables-what-you-need-to-know-about-s.html http://chargen.matasano.com/chargen/2007/9/7/enough-with-the...
- aidenn0 16y agoThat article actually states that salting is a real security practice, is a necessity, and that it's been in UNIX since 1976,
- frisco 16y agoI was more talking about bcrypt being consensus with that post. Salting slows down cracking attempts by a factor of N where N is the length of the hash; md5 and sha1 are so fast that you shouldn't be banking on salting to protect you in 2010. Also, you should assume that if an attacker has your database (with salts), they also have your code, which tells them exactly how the salt was applied. In that case, salting doesn't slow you down at all.
- bostonvaulter2 16y agoI think the point is that you should use bcrypt and salt at the same time.
- tptacek 16y agoYou don't need to do anything like that; bcrypt does all this stuff for you. Don't salt bcrypt.
- jmillikin 16y ago"It’s important to note that salts are useless for preventing dictionary attacks or brute force attacks. You can use huge salts or many salts or hand-harvested, shade-grown, organic Himalayan pink salt. It doesn’t affect how fast an attacker can try a candidate password, given the hash and the salt from your database." Why are you storing the whole salt in your database? Isn't it much more common to keep half of it in a configuration file? I know Django has a SECRET_KEY parameter for this sort of thing, and hopefully other frameworks do also. For that matter, why is authentication being handled by the web server? If you've got data worth stealing (billing, emails, medical), you can afford to spring the extra few hundred for a proper authentication server. Gawker's password handling (7-bit salt, in the database, digested with crypt) seems like the worst possible implementation of secure password storage.
- beej71 16y agoIf you want to crack passwords ultrafast, you make a look-up table of the hashes of all probable passwords. Without a salt, this is rather a smaller table. A 7-bit salt makes the table larger, but not hugely larger, and not troublesomely larger. The 128-bit salt used by bcrypt makes the table intractably hugely large. You cannot precompute it. Of course, you know the salt (because it's stored right there in /etc/shadow), so you can still run through dictionary words and try them all. But bcrypt is designed to take arbitrarily long amounts of real time to do this. So in the case of bcrypt, it's not really an issue that the salt is stored right there alongside the hashes password.
- tptacek 16y agoThose password crackers that are belting through billions and billions of passwords an hour with just a couple of video cards aren't using rainbow tables, are they? You could have zero bit salt: you're still boned. Bcrypt is not better because it has a better salt. It's better because one iteration of bcrypt takes a long time, and millions of iterations take an intractably long time.
- beej71 16y ago
- Cushman 16y agoI wonder, is it easy to use bcrypt with a variable work factor per-password? I'm thinking you could take your entropy analysis of the user's password and set it so that "weaker" passwords use a higher work factor. This analysis could be easily done before hashing every time the password is input, so an attacker wouldn't be able to single out weak passwords from the hash file. Theoretically, you should be able to tailor the numbers so that cracking a weak password isn't any faster than cracking a strong one, right? Plus it will encourage your users to use a stronger password in the first place, since it'd make login slightly faster. Any obvious problems with this plan?
- tptacek 16y agoIt's not hard to do this (with Ruby bcrypt, it's 2 lines of code using the public interface), but I think you're overthinking it. Most users will use crappy passwords. Set the work factors uniformly high.
- Cushman 16y agoDefinitely a good point. I feel like it might still help you to avoid wasting time exhaustingly hashing already strong passwords. I mean, how high does that uniform work factor have to be? The guy whose password is "password" or "qwerty12" is gonna get cracked no matter what, sure. But what about people whose passwords are a couple of dictionary words? If the work factor means each hash takes a second or two, even a slightly complex dictionary attack becomes fruitless (for most crackers...) So the user can still log in, but it takes a second or two, and there's that little message, "To ensure the safety of your password, your login has been slowed down. If you use a more secure password, like <generate password>, you will login much faster!" And the young lady using "6ab$TRa?" isn't being punished for the fact that most users use crappy passwords, nor is your server.
- tptacek 16y agoYou're overthinking both the security aspect of this and the performance aspect of it. User-imperceptible hash times are adequate to make most conceivable brute force attacks intractable.
- bostonvaulter2 16y agoIf you have a 5-year old database using a given bcrypt work factor, how difficult is it to transition to a new, higher work factor?
- pavel_lishin 16y agoFollow-up question: I assume this also means that it would result in new hashes for the same passwords?
- wladimir 16y agoYes. But from what I understand, that's even the case if you bcrypt() the same password with the same load factor multiple times, as it uses a random salt.
- miGlanz 16y agoImagine this Python code (I'm using SHA1 iterated multiple times, basically PBKDF2): import hashlib hashed = password for i in range(50000): hashed = hashlib.sha1(salt + hashed) Provided we also store the number of iterations (along with the salt), and provided I didn't do anything stupid above, we could simply add more iterations after these 5 years and update hash and number of iterations field. Would it be a viable solution?
- timtadh 16y agoB-crypt and S-crypt are great libraries to use to solve this problem. However, the poor man's approach is as follows with HASH being your favorite hash function h = HASH.new() HASH.update(password) HASH.update(salt) for x in xrange(X): HASH.update(HASH.digest()) return HASH.digest() this approach "strengths" the hash by forcing you to calculate it over and over again. You should set X to be the number of rounds you want to conduct. Ie. how slow you want you server to respond to an individual request. It is always a trade-off between server slowness for individual requests and "security" of the hash function. The goal is to make dictionary attacks take longer than is feasible for you attackers to conduct. [Note: you should absolutely have a different salt for each password with this approach.]
- tptacek 16y agoFor what it's worth: this is essentially PBKDF2.
- cperciva 16y agoActually, it's essentially PBKDF1, but that's close enough for non-cryptographers.
- tptacek 16y agoShit, you're right. (PBKDF2 generates arbitrary-length output, which is what you want from a key derivation function, but maybe not something you care about for a password hash). Here's a version that's much easier to read than the spec: https://github.com/emerose/pbkdf2-ruby/blob/master/lib/pbkdf2.rb https://github.com/emerose/pbkdf2-ruby/blob/master/lib/pbkdf... I should stop saying PBKDF2 and just go back to saying PBKDF.
- cperciva 16y agoPBKDF2 also protects against entropy loss from repeated iteration, although that doesn't really matter unless you're using an unreasonably short hash.
- adulau 16y agoWhen seeing the title, I was expecting an article about CMAC or HMAC or even PBKDF2-like function but it's the "old" bcrypt.
- mfukar 16y agoYou say that as if it's a bad thing. EDIT: Oh, you mean it was similar to other submissions. Fair enough.
- adulau 16y agoNot really. Just it was already mentioned sometimes ago about the fixed cost function in bcrypt: http://news.ycombinator.com/item?id=762708 http://news.ycombinator.com/item?id=762708
- mcgin 16y agoI made an attempt to implement bCrypt on the last web app I built. The problem I found with it is that there was no robust implemention of the algorithm for the tech stack I was using (J2EE) - I'm not sure whether that is the case outside of Java. jbCrypt was the only thing I could find, and if you look at the source, it really is a poor implementation. I could have gone ahead and rolled my own implementation, however I'm no security expert, and much prefer to rely on something more robustt then my own implementation which in all likelihood would have bugs in it.
- shabble 16y agoThe part that I don't quite understand about bcrypt and the "scales with hardware speed" claim, is that, as I understand it, validating a password requires 3 parameters; password string, salt, and cost factor. If you start out now with some given cost factor, that is unfeasibly breakable with modern hardware, that factor will remain stored somewhere, presumably in the database. Once computing hardware speeds up to the point that your factor is now practical to break, you can increase the cost factor for new passwords, but older ones remain susceptible to cracking. The only option would be to re-encode them periodically with the new factor to keep them secure. Can anyone clarify if I've understood this correctly, or if I'm missing something fundamental about bcrypt? I've looked over the usenix paper, but I can't see anything obvious to confirm one way or the other.
- Strilanc 16y agoIf you're using bcrypt then the client has transmitted the password to you. You can store a higher cost hash after verifying the password against the old hash.
- niels_olson 16y agoFun fact: this has been posted to Hacker News before, when it first came out. I think most would agree this is a great example of why re-posting should be allowed. http://news.ycombinator.com/item?id=1091104 http://news.ycombinator.com/item?id=1091104
- bigiain 16y ago+1 Thanks to codahale for writing this, r11t the HN user who originally posted this early this year, and the discussion by everyone on that HN thread which convinced me of the correctness of the bcrypt approach. I've already shipped one project which I'm sure at least part of the reason we successfully pitched was our demonstrated indepth understanding of password security requirements. (I also realised in retrospect that a project I'd designed and specced before reading that article/discussion was going to be wrong in it's password handling, I'm disappointed we never got to build that product, but I'm kinda glad I'm not sitting here thinking "Fuck, what am I gonna do if $project's database ever gets compromised? It'll be just as bad as Gawker...")
- IgorPartola 16y agoI admit I games the system a bit to re-post this link, but it seemed very relevant. I learned a ton from this discussion, so my selfish reasons were met.
- 16s 16y agoMicrsoft Active Directory stores what it calls an NT Hash in NTDS.DIT files on domain controllers. These are unsalted, md4 hashed, unicode strings. They are fast and easy to crack if you ever do get your hands on them. The point is that many big companies don't do passwords right, so why expect Gawker to do so? Edit: md4 is not a typo. They use md4 not md5... OK.
- count 16y agoAnd that's not the only place they're stored (assuming the default cached credentials setting is still in place). Also, with the advent of pass-the-hash, you don't need to crack Windows AD passwords to use them anymore. Just having the hash is enough for loads of fun.
- Waywocket 16y agoWorse, Windows up to Server 2003 by default stores LAN Manager hashes as well. To describe the cracking of these as 'trivial' would trivialise the work 'trivial'.
- tocomment 16y agoSome everyone is saying how easy it is to crack md5. Say I have an md5 hash and I know it was created from a 1000 byte string. How long would it take to enumerate all 1000 byte strings that could create that hash?
- gxti 16y agoActually you can (almost surely) stop cracking at 16 bytes, because that's how long MD5 digests are and any more bits than that are going to give you hashes you've already seen. You won't get back the original string but you don't need the original string.
- seunosewa 16y agoActually, you have to go a bit beyond 16 bytes to be sure.
- joeguilmette 16y agoI use a different password for every website. It is easy to remember, I just have a portion of my password that changes for every website. For example: dg76fb23S for Facebook, dg76fb23S for hacker news Been working great for years :)
- steveklabnik 16y agoYour Facebook and HN passwords are the same? ;) And if someone ever sees these in plaintext, it's trivially extrapolate-able to other sites. Dunno.
- Raphael 16y ago>dg76fb23S for Facebook, dg76fb23S for hacker news So you use the same password for everything.
- city41 16y agoMy issue is asking a lot of people to change their password because I've decided to change my encryption algorithm. Is there a best practice for upgrading encryption without forcing users to do that? Something like when the user logs in, hold onto their plaintext password for a bit, confirm it's correct against your current algorithm, and then re-encrypt it with bcrypt?
- dangoldin 16y agoGood question. My gut instinct would be to do just that but I wonder if there's a better way. You'd probably also want to track the encryption of each user so you know when you can make the final switch. Another alternative is to just send "update your password" emails to everyone framing it as an improvement to your site's security.
- Waywocket 16y ago>Another alternative is to just send "update your password" emails to everyone framing it as an improvement to your site's security. I guarantee everyone with a decent spamfilter will miss those e-mails - that looks exactly like a standard phishing attempt.
- niktech 16y agoWhy not do it behind the scenes? Simply use the existing MD5/SHA1 hash as input to bcrypt and update all password hashes in your database in one go. Then, whenever the user logs in you first apply the old hash function followed by bcrypt before comparing with what you have in the DB.
- city41 16y agoNice, thanks. This is why I asked. That approach had not occured to me.
- Seth_Kriticos 16y agoWhat the article tries to say is, that your password hashing function needs three attributes: * it has to be dog slow (to make brute forcing hard) * it should be complicated enough to avoid collisions (this really applies to most hash functions) * it should be suitably salted, to avoid rainbow tables -> bcrypt is designed like this, if in doubt, use it
- pmjordan 16y agoThe Java implementation linked from the article, jBCrypt, http://www.mindrot.org/files/jBCrypt/jBCrypt-0.2-doc/ http://www.mindrot.org/files/jBCrypt/jBCrypt-0.2-doc/ uses java.lang.String's compareTo() function (lexicographical comparison) to validate the hashes of passwords. Is there cause for concern about this in practice, considering it will probably have varying runtimes for different match lengths? (I realise that running in a JITted VM means I can't predict the assembly language produced anyway)
- boscomutunga 16y agoI think sooner or later computing power is going to increase to the point of making bicrypt look like md5 or lesser,i think what matters is protecting the hash.
- iana 16y agoIf an attacker steals a DB of passwords, it is only a matter of time before computing power catches up and is able to crack the list, regardless of the methods used to hash the values. Advances in cryptography are rare, advances in processor capabilities are not. bCrypt may be the best we can do at this point to delay this inevitability, but programmer's shouldn't come away from this thinking that using bCrypt "solves" this problem. An interesting question related to this is how long a time period is considered "safe" enough to protect a stolen list? If the list is protected from brute-force cracking for 3 years after theft, is that enough time to render the passwords unusable? 5 years? It seems like the answer to this question would be used to calculate an appropriate value for bCrypt "speed".
- easysecured 16y agoWhat if there are no passwords to start with. If users do not enter a password and instead a hashed key is generated for the device used by the user which then encrypts everything before it is stored on the server. This key could be generated in real time and would not be displayed anywhere on the form and will be transferred in stealth mode to the server. With no passwords to enter or transmit, there will be nothing to hack.... If the key generated in origin is itself a strong key decrypting information stored on the server will require first hacking the key which if not stored on the server in the first place will make life hell for hackers as they will require access to the individual devices as well. Cheers, gurudatt