Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Slightly related, in order to prevent super long passwords from eating up CPU time is it better to hash using sha256 before argon/bcrypt so that the length is constant, or is it better to limit password length to some arbitrary number like 64 characters


I've been tempted a few times to simply use salt and a single iteration SHA-256 to store passwords, and put something like this on the account creation and password change screens:

> If you care about the security of your account use a 20+ character random password and do not reuse that password at any other sites. There are several excellent password managers that can generate and remember such a password for you and make it easy to use. Here's a list: <link to list of password managers>.

> We allow all normal US printable characters in your password: upper and lower case A-Z, digits, and <list of punctuation>. Set your password generator to length 20+ and to use mixed case, digits, and symbols and you will be fine.

> If you think you might have to manually type this password at some point, you can use a reduced character set with a longer password. If you use just mixed case letters and digits make the password 22+ characters long. If you use just mixed case letters make it 23+ characters. Letters all of the same case? Make it 28+ characters. 32+ characters of hex is fine, too. Heck, you can make it all digits if you use at least 39 of them.

> If your password manager offers other options, such as patterns like groups of digits or pronounceable syllables separated by some symbol, that too is fine as long as you make it long enough. Make it long enough that your password manager gives it its highest strength rating.

> The exact upper limit on password length that our password entry fields allow might vary from time to time as we update the site, but will always be at least 64 characters.


What's wrong with super long passwords eating up CPU time? Can't imagine it is that prevalent with normal users and there are other ways to deal with it if it is a vector for a DOS attack (rate-limiting the number of registrations or logins, for example).

NIST says there's no reason to limit password length any more[0]:

"Memorized secrets SHALL be at least 8 characters in length if chosen by the subscriber. Memorized secrets chosen randomly by the CSP or verifier SHALL be at least 6 characters in length and MAY be entirely numeric. If the CSP or verifier disallows a chosen memorized secret based on its appearance on a blacklist of compromised values, the subscriber SHALL be required to choose a different memorized secret. No other complexity requirements for memorized secrets SHOULD be imposed. A rationale for this is presented in Appendix A Strength of Memorized Secrets."

0: https://pages.nist.gov/800-63-3/sp800-63b.html


> to prevent super long passwords from eating up CPU time

Is that why websites sometimes have low maximum password length requirements ? Ex: must be less than 20 characters.


Super long is >100 character passwords. Not much point: either the hash function is broken or some other hack will happen before humanity develops enough compute power to crack 100 char bcrypt passwords.

Websites (like some banks used to) that have less-than 20 char limits for passwords are purely bad security strategy.


You know what the worst is? When they limit you to, say, 20 or 32 characters, but accept a longer password and silently truncate it!

I've run across that at least once and it was a total pain to troubleshoot and figure out.


The number of sites that restrict passwords to 20 characters drives me nuts!

There needs to be a limit, yes, but surely something like 100 characters, or even 50, would be more sensible.


And it's the same websites that tend to use the bad practice of forcing the use of 2-4 "types" of characters...


like some banks used to

Banks all have systems that will stop you from attempting to bruteforce them.


The CPU usage difference between a hash on 20 bytes vs 100 (assuming ASCII) can't be that bad, can it?


We are not talking about 100 bytes of password here, but megabytes of garbage. See https://www.djangoproject.com/weblog/2013/sep/15/security/, also known as CVE-2013-1443.

"A password one megabyte in size, for example, will require roughly one minute of computation to check when using the PBKDF2 hasher."


I think an average user password would be shorter than a sha256 hash no?


Bcrypt truncates to 72 bytes, so it's kind of irrelevant IMO. Whether your average length is 12 or 20 or 64 bytes doesn't matter much.

I expect the parent's concern came from experience with PBKDF2, where the length is unbounded. It's good to consider possible denial of service attacks: if someone submits an enormous 1 MB password a PBKDF2 hasher can be knocked offline for 60s. Sha256 will quickly crunch that attack to a more manageable length.


Exactly this, it’s a vector for DOS


> Many implementations of bcrypt truncate the password to the first 72 bytes, following the OpenBSD implementation.

https://en.m.wikipedia.org/wiki/Bcrypt

This sounds undesirable to me, so I'd support sha256 and an alternative.

I'd also recommend adding a max password length to any API. No point in allowing million character passwords.


I'm guessing folks are reading that as endorsement or sha256 over bcrypt. In context with the above post, this is sha256 over truncation.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: