ChatGPT解决这个技术问题 Extra ChatGPT

Should I impose a maximum length on passwords?

I can understand that imposing a minimum length on passwords makes a lot of sense (to save users from themselves), but my bank has a requirement that passwords are between 6 and 8 characters long, and I started wondering...

Wouldn't this just make it easier for brute force attacks? (Bad)

Does this imply that my password is being stored unencrypted? (Bad)

If someone with (hopefully) some good IT security professionals working for them are imposing a max password length, should I think about doing similar? What are the pros/cons of this?

There almost certainly is a "three strikes and you are out" policy, which eliminates the threat of a brute force attack.
There is no excuse for this for non-legacy systems, like modern-day websites.
I don't think the answer is purely IT. The minimum size (6) and a maximum limit of attempt is "likely" to eliminate wild guesses. My guess is that the maximum size (8) is to limit the number of call (and consequently the cost) of the support for the "Oops I forget mycode" or "I type the code to fast" or "I mistype one characters" etc. In addition of the paper on which you write the password if you can't remember it..
The university im enrolled in has insanely stupid password rules: 8 chars only, at least 1 number, but not in the beginning or end of the password, needs chars from more than the 2 upper rows of the keyboard etc. etc. In the end they make bruteforcing easier by having these rules -.- . I realize you aint that stupid, but please don't make silly rules like that! (Just had to get it out of my system :) )
@call Well if you impose a max length for that reason then you will get "I forgot my password" calls from me, because my site-unique passwords are all long, and limiting me to 12 chars is a sure way to guarantee I will not remember it.

C
Community

Passwords are hashed to 32, 40, 128, whatever length. The only reason for a minimum length is to prevent easy to guess passwords. There is no purpose for a maximum length.

The obligatory XKCD explaining why you're doing your user a disservice if you impose a max length:

https://imgs.xkcd.com/comics/password_strength.png


Perhaps a bank might choose to limit the password because on ATMs you can't input more than, say, 8 characters.
well at least on ATMs, if you try a brute force attack, it'll eat your card. What I'm referring to is the password for logging on online only though.
Sadly that assumes that the passwords are always hashed. Maximum length passwords are a symptom of passwords stored in plaintext.
Sigh, even at PayPal, "correct horse battery staple" is 8 characters above their maximum length... headdesk
@kleinfreund because if it was hashed, the password length wouldn't matter to them (hash functions convert a string of any length to a fixed length).
u
unforgettableidSupportsMonica

A maximum length specified on a password field should be read as a SECURITY WARNING. Any sensible, security conscious user must assume the worst and expect that this site is storing your password literally (i.e. not hashed, as explained by epochwolf).

In that that is the case:

Avoid using this site like the plague if possible. They obviously know nothing about security. If you truly must use the site, make sure your password is unique - unlike any password you use elsewhere.

If you are developing a site that accepts passwords, do not put a silly password limit, unless you want to get tarred with the same brush.

[Internally, of course your code may treat only the first 256/1024/2k/4k/(whatever) bytes as "significant", in order to avoid crunching on mammoth passwords.]


I also send such websites a standard email, mentioning that they forced me to use a shorter, less secure password, that I also happen to reuse on every website that imposes such silly limits. This lets them know that it's a problem and also might give a Joe Coder some leverage to show to the higher-ups: evidence that users actually think badly of the website as a result of this.
I'm not sure you should assume that a password maximum means they are storing plain text passwords. Sometimes, they are truncating the input, and simply passing the first x chars into the hashing(). (The way to check is set a password to beyond the limit, then try to login with a variation of the password characters beyond the max-length).
@benc sure, that's possible, but the point is that as a user you have no way of knowing if this is what they are doing. A max-length (especially a short one) is a warning sign and I think it's best to assume the worst (or get in touch with the provider to get them to confirm).
Please elaborate. This answer is a mere statement.
A maximum password doesn't necessarily mean it's being stored as plain text; it can be for technical reasons, for instance bcrypt only allows passwords up to 72 characters.
J
Jason Dagit

Allowing for completely unbounded password length has one major drawback if you accept the password from untrusted sources.

The sender could try to give you such a long password that it results in a denial of service for other people. For example, if the password is 1GB of data and you spend all your time accept it until you run out of memory. Now suppose this person sends you this password as many times as you are willing to accept. If you're not careful about the other parameters involved this could lead to a DoS attack.

Setting the upper bound to something like 256 chars seems overly generous by today's standards.


You can still send 1gb of data with a maximum limit. The software doing the limiting is almost always behind the webserver.
You can still drop all but the first 256chars before doing something computationally intensive though. Running a sha hash on 1gb of data is going to take much longer than the same hash on 256 chars.
@Eyal: Anything that happens on the client side of a web app is inherently untrusted; thus, the hash becomes a password equivalent, making this an exercise in futility. (a web browser probably won't accept a 1-GB text input, and a custom client might send a 1-GB string in the "thisisthehashedpassword" form field)
@Piskvor: But there is no way to prevent the 1-GB string anyway. A user can always request example.com/?password=abcabcabcabc ... and make his request as big as he wants. Standard DoS.
@Piskvor and Eyal, fortunately, Apache and IIS (and presumably other mature servers) limit the length of fields passed via URLs: boutell.com/newfaq/misc/urllength.html
S
Sparr

First, do not assume that banks have good IT security professionals working for them. Plenty don't.

That said, maximum password length is worthless. It often requires users to create a new password (arguments about the value of using different passwords on every site aside for the moment), which increases the likelihood they will just write them down. It also greatly increases the susceptibility to attack, by any vector from brute force to social engineering.


Agreed! Look at that the string of UK bank online access security failures of the past few years...
I already use a different password on every website through a scheme that lets me remember them all, but they are all rather long. The only websies whose passwords I write on sticky notes are those which impose moronic max length limitations and thus force me away from my preferred yet unique password...
@romkyns I take it your scheme does not use symbols? I had such a scheme once that produced short hard-to-brute-force passwords, but I had to abandon it when 10-20% of the sites I used forbid common special characters.
no special characters, no, but it always adds numbers and uppercase chars, because I knew some sites demand that. Wish I had known about the max length limits when I came up with it... But the (simpler) schemes I made up for close relatives have worked perfectly so far!
@romkyns other problems with such schemes: sites that share passwords. If your scheme is something like nameofwebsitefO0 (googlefO0 yahoofO0 etc) then how do you remember that you're supposed to use "yahoofO0" on flickr.com, or stackoverflowfO0 on askubuntu.com? sites that expire passwords. then you need to extend the scheme to include a part that can change. but that fails if the expiration rule checks for substrings.
A
ABM

Setting maximum password length less than 128 characters is now discouraged by OWASP Authentication Cheat Sheet

https://www.owasp.org/index.php/Authentication_Cheat_Sheet

Citing the whole paragraph:

Longer passwords provide a greater combination of characters and consequently make it more difficult for an attacker to guess. Minimum length of the passwords should be enforced by the application. Passwords shorter than 10 characters are considered to be weak ([1]). While minimum length enforcement may cause problems with memorizing passwords among some users, applications should encourage them to set passphrases (sentences or combination of words) that can be much longer than typical passwords and yet much easier to remember. Maximum password length should not be set too low, as it will prevent users from creating passphrases. Typical maximum length is 128 characters. Passphrases shorter than 20 characters are usually considered weak if they only consist of lower case Latin characters. Every character counts!! Make sure that every character the user types in is actually included in the password. We've seen systems that truncate the password at a length shorter than what the user provided (e.g., truncated at 15 characters when they entered 20). This is usually handled by setting the length of ALL password input fields to be exactly the same length as the maximum length password. This is particularly important if your max password length is short, like 20-30 characters.


This source doesn't discourage maximum password length limits, it discourages low (less than 128 characters) maximum password length limits.
Thanks for the reference! Although nowadays (2020) their recommendation has changed due to some restriction on the hashing algorithms. Ex 64 characters for a system using Bcrypt.
The referenced cheat sheet now explicitly states, that you should have a password length limit set: "It is important to set a maximum password length to prevent long password Denial of Service attacks.".
m
mbac32768

One reason I can imagine for enforcing a maximum password length is if the frontend must interface with many legacy system backends, one of which itself enforces a maximum password length.

Another thinking process might be that if a user is forced to go with a short password they're more likely to invent random gibberish than an easily guessed (by their friends/family) catch-phrase or nickname. This approach is of course only effective if the frontend enforces mixing numbers/letters and rejects passwords which have any dictionary words, including words written in l33t-speak.


While understandable, legacy systems sometimes have to dictate design. Wheverever possible they should NOT influence it. The last thing you want in a new system is one with a security policy designed before modern security attacks were even common. Or worse, newer software but incorrectly designed in the first place. An existing corporate system may use HTTP but that's no justification to not use SSL in a new system or extension. Likewise, password policies shouldn't continue to be vulnerable just because the LAST guys did it wrong.And if keeping, there had better be a HUGE cost/benefit study.
A
AardvarkSoup

One potentially valid reason to impose some maximum password length is that the process of hashing it (due to the use of a slow hashing function such as bcrypt) takes up too much time; something that could be abused in order to execute a DOS attack against the server.

Then again, servers should be configured to automatically drop request handlers that take too long. So I doubt this would be much of a problem.


I just debugged a password problem and found that bcrypt only uses first 72 bytes. if password is longer, no error. so if first 72 are the same but anything after is different, the password will validate.
L
Lucas Oman

I think you're very right on both bullet points. If they're storing the passwords hashed, as they should, then password length doesn't affect their DB schema whatsoever. Having an open-ended password length throws in one more variable that a brute-force attacker has to account for.

It's hard to see any excuse for limiting password length, besides bad design.


D
DrStalker

The only benefit I can see to a maximum password length would be to eliminate the risk of a buffer overflow attack caused by an overly long password, but there are much better ways to handle that situation.


There should be a maximum input length, yes, but it should definitely not be < 64. A maximum length of 8 or 12 is just ridiculous.
C
CommonSenseCode

Ignore the people saying not to validate long passwords. Owasp literally says that 128 chars should be enough. Just to give enough breath space you can give a bit more say 300, 250, 500 if you feel like it.

https://www.owasp.org/index.php/Authentication_Cheat_Sheet#Password_Length

Password Length Longer passwords provide a greater combination of characters and consequently make it more difficult for an attacker to guess. ... Maximum password length should not be set too low, as it will prevent users from creating passphrases. Typical maximum length is 128 characters. Passphrases shorter than 20 characters are usually considered weak if they only consist of lower case Latin characters.


Not relevant to the discussion. The question is whether there's any benefit to limiting the length not whether 128 is enough.
V
Vincent McNabb

My bank does this too. It used to allow any password, and I had a 20 character one. One day I changed it, and lo and behold it gave me a maximum of 8, and had cut out non-alphanumeric characters which were in my old password. Didn't make any sense to me.

All the back-end systems at the bank worked before when I was using my 20 char password with non alpha-numerics, so legacy support can't have been the reason. And even if it was, they should still allow you to have arbitrary passwords, and then make a hash that fits the requirements of the legacy systems. Better still, they should fix the legacy systems.

A smart card solution would not go well with me. I already have too many cards as it is... I don't need another gimmick.


They cut out important keyspace that lengthens to time for brute force attacks when (and I mean WHEN) their database of hashes is stolen (assuming they even salt/hash/stretch, which I'm sure they don't). Time to change banks.
U
User

If you accept an arbitrary sized password then one assumes that it is getting truncated to a curtain length for performance reasons before it is hashed. The issue with truncation is that as your server performance increases over time you can't easily increase the length before truncation as its hash would clearly be different. Of course you could have a transition period where both lengths are hashed and checked but this uses more resources.


M
Marek Puchalski

Try not to impose any limitation unless necessary. Be warned: it might and will be necessary in a lot of different cases. Dealing with legacy systems is one of these reasons. Make sure you test the case of very long passwords well (can your system deal with 10MB long passwords?). You can run into Denial of Service (DoS) problems because the Key Defivation Functions (KDF) you will be using (usually PBKDF2, bcrypt, scrypt) will take to much time and resources. Real life example: http://arstechnica.com/security/2013/09/long-passwords-are-good-but-too-much-length-can-be-bad-for-security/


L
LizB

Storage is cheap, why limit the password length. Even if you're encrypting the password as opposed to just hashing it a 64 character string isn't going to take much more than a 6 character string to encrypt.

Chances are the bank system is overlaying an older system so they were only able to allow a certain amount of space for the password.


Unless there is a very valid reason, passwords should hashed. Hashes result in fixed length strings. There is not space argument to make, unless the system is storing the actual password, which is arguably a terrible idea.
Encrypting passwords is a terrible idea. An unscrupulous employee is all it takes for you to leak a gazillion passwords. Save the trouble by never storing them in the first place.
t
tekiegreg

Should there be a maximum length? This is a curious topic in IT in that, longer passwords are typically harder to remember, and therefore more likely to get written down (a BIG no-no for obvious reasons). Longer passwords also tend to get forgotten more, which while not necessarily a security risk, can lead to administrative hassles, lost productivity, etc. Admins who believe that these issues are pressing are likely to impose maximum lengths on passwords.

I personally believe on this specific issue, to each user their own. If you think you can remember a 40 character password, then all the more power to you!

Having said that though, passwords are fast becoming an outdated mode of security, Smart Cards and certificate authentication prove very difficult to impossible to brute force as you stated is an issue, and only a public key need be stored on the server end with the private key on your card/computer at all times.


People can easily remember a favorite song lyric, bible verse, or other saying. Those are very long compared to a typical password. I just tested one and came in at 79 characters! (Granted, the possibility of a mistake goes up the longer a passphrase is. Even worse when a STUPID website doesn't show you the last character you entered in the password box.)
b
benPearce

Longer passwords, or pass-phrases, are harder to crack simply based on length, and easier to remember than requiring a complex password. Probably best to go for a fairly long (10+) minimum length, restricting the length useless.


佚名

Legacy systems (mentioned already) or interfacing outside vendor's systems might necessitate the 8 character cap. It could also be a misguided attempt to save the users from themselves. Limiting it in that fashion will result in too many pssw0rd1, pssw0rd2, etc. passwords in the system.


C
Chris J

One reason passwords may not be hashed is the authentication algorithm used. For example, some digest algorithms require a plaintext version of the password at the server as the authentication mechanism involves both the client and the server performing the same maths on the entered password (which generally won't produce the same output each time as the password is combined with a randomly generated 'nonce', which is shared between the two machines).

Often this can be strengthened as the digest can be part computed in some cases, but not always. A better route is for the password to be stored with reversible encryption - this then means the application sources need to be protected as they'll contain the encryption key.

Digst auth is there to allow authentication over otherwise non-encrypted channels. If using SSL or some other full-channel encryption, then there's no need to use digest auth mechanisms, meaning passwords can be stored hashed instead (as passwords could be sent plaintext over the wire safely (for a given value of safe).


f
fake girlfriends

Microsoft publishes security recommendations for developers based on their internal data (you know, from running the biggest software enterprise in the history of computing) and you can find these PDFs online. Microsoft has said that not only is password cracking near the least of their security concerns but that:

“Criminals attempt to victimize our customers in various ways and we’ve found the vast majority of attacks are through phishing, malware infected machines, and the reuse of passwords on third-party sites—none of which are helped by very long passwords." -Microsoft

Microsoft's own practice is that passwords can be no longer than 16 and no shorter than 8 characters.

https://arstechnica.com/information-technology/2013/04/why-your-password-cant-have-symbols-or-be-longer-than-16-characters/#:~:text=Microsoft%20imposes%20a%20length%20limit,no%20shorter%20than%20eight%20characters.


d
dewd

I found using the same characters for the first 72 bytes of a password gives a successful verification using password_hash() and password_verify() in PHP, no matter what random string comes after the first 72 bytes.

From PHP docs: https://www.php.net/manual/en/function.password-hash.php

Caution: Using the PASSWORD_BCRYPT as the algorithm, will result in the password parameter being truncated to a maximum length of 72 bytes.


u
user17000

Just 8 char long passwords sound simply wrong. If there ought to be a limit, then atleast 20 char is better idea.


But that's the thing - there ought to not be a limit at all.
J
Josh Hunt

I think the only limit that should be applied is like a 2000 letter limit, or something else insainly high, but only to limit the database size if that is an issue


Passwords should be hashed... And database size wouldn't be an issue is the password is hashed.
@epochwolf – I can think of one reason why passwords shouldn't always be hashed (because I discovered it myself today): a password that needs to be submitted to a third party on behalf of the user can't be stored as a hashed value. [E.g. an application that needs to store credentials for sending emails thru an external domain.]