views:

576

answers:

9

Without thinking about it at all I just want to say I should allow every character. It gets hashed in any case, and I don't want to limit people who want to create strong passwords.

However, thinking about it more, there are plenty of characters that I have no idea what effect they'd have on things. Foreign characters, ascii symbols, etc. to name a couple.

I tried to Google but I can't find any definitive standard for what people do. Even most professional organizations don't seem to know. It seems to be a common practice for many sites to disallow special characters altogether, which is just silly and not what I want to do.

Anyway, are there any standard recommendations for length, allowed characters, and so forth?

I'm not sure if it matters, but I'll be using ASP.NET w/ C#

+3  A: 

Not an expert, but I hate when characters I choose and not that bizarre are rejected. So, I think I agree with your gut.

kenny
+6  A: 

Non-ASCII characters certainly make things harder when it comes to entering the password on limited devices (mobiles, consoles etc) - but usually not impossible. Arguably if the user wants to do that, you should let them. It's easy enough to do a reasonable and consistent thing - encode in UTF-8 before hashing, for example. You'd only get into difficulties if some input device sent the characters as a composition (e.g. e + acute accent instead of "e acute") - but I suspect that wouldn' t happen in real life. (You could decompose everything yourself, but that would be a lot of trouble to go to for an edge case.)

I'd restrict it to printable characters, however. Putting tabs, form feeds etc in a password really is asking for trouble.

Jon Skeet
As long as it hashes it the same way it shouldn't be a problem, should it?
some
The problem is that characters cannot be distinguished/identified by human eyes will make it difficult to trace/debug.
PolyThinker
The tab character has a special "autocomplete" action on most browsers. What if users couldn't type it? Ask them to copy and paste from Notepad?
chakrit
@chakrit: Exactly, that's not a printable character, so I'd avoid it.
Jon Skeet
If you can't type it, it would be hard to enter it in the first place, presuming you're using the same interface.
chaiguy
@chaiguy1337: That presumption is the problem. I regularly use different devices for the same site.
Jon Skeet
@polythinker: Passwords should never, ever, ever be displayed to a user. Ever. Any issues with them being unclear when displayed to a user are, therefore, moot.
Dave Sherohman
@Jon: That presumption is not a problem. You know what devices you are likely to use and can self-limit the characters used accordingly. Other users use different sets of devices and can choose their passwords accordingly. This does not call for the app to impose external limits on all users.
Dave Sherohman
@Dave: When I started on StackOverflow, I didn't have an Android phone. Now I post with it occasionally. Is there really a good reason for allowing a user to include tab or form-feed in a password? Sure, allow symbols etc - but non-printable characters?
Jon Skeet
@Dave: I *completely* agree about passwords never being shown though. I get *very* cross when I register with a site, choosing a password, and it then *emails* me the password in plain text. Aargh!
Jon Skeet
+10  A: 

Any printable, non-whitespace ASCII character (between 33 and 126 inclusive) are typically allowed in passwords. Many security professionals (and SO commenters) are advising the use of a passphrase in place of a password, so you'd have to allow spaces. The argument is that due to their length, and since phrases aren't in a dictionary, passphrases are more difficult to crack than passwords. (A passphrase can also be easier to remember, so a legitimate user doesn't have to keep it written down on a sticky-note right on their monitor.)

Some strong password generators use a hash, so I'd put a very high limit on the length (512 or 1024) just to be inclusive. Password generators today often yield strings of 32-128 characters, but who knows what hashes will be used in the next few years.

Bill the Lizard
And I want to use åäöÅÄÖ and other non ASCII characters. Its time to use unicode. Just UTF-8 encode it and then hash it.
some
Good point. I don't know of any reason that unicode shouldn't be used.
Bill the Lizard
I'd even argue that whitespace should be allowed (at least U+0020, the traditional space), since for security-reasons using a passphrase (as opposed to a password) might be preferable.
Joachim Sauer
Yes, I'd allow space, but probably no other whitespace.
Jon Skeet
I agree with @saua. I sometimes use a space in my passwords.
Hosam Aly
Another good suggestion. I'll edit to add that.
Bill the Lizard
Why limit on whitespace? If it can be encoded/hashed for storage, it's the user's prerogative as to what should be entered.Scott Meyers calls this the "keyhole problem." http://www.aristeia.com/TKP/draftPaper.pdf
mskfisher
A: 

If you are talking about preventing SQL-injection type of attacks, it is probably a better idea to make sure your code does what it is supposed to do, rather than relying on restricting the input so the problem becomes easier.

For non-ascii characters, I don't see that as a more difficult problem if your input can be correctly represented as a binary string (and not as text), which is then passed to your hash function or key generator, etc.

PolyThinker
+2  A: 

Fundamentally, most of the unicode class of characters should be allowed. Do skip however control characters (e.g. 0-31 besides space), the byte order mark (0xfffe and oxfeff). Further, you want to first canonicalize the representation to get rid of problems caused by differing representations. You might issue warnings though for characters that seem to be too hard to enter, but users will guard against that themselves.

Paul de Vrieze
On the other hand, characters that are "too hard to enter" could actually be a security feature.
chaiguy
+2  A: 

Short answer: allow as much as the system backing it can support. Nowadays there's really no excuse not to use full unicode support for text entry, and that includes passwords. I don't think you need to worry about problems with characters as long as they're handled literally (but I'm not a pro in this field--beware of sql injection).

I have a pet peeve against sites that impose restrictions on passwords... any kind of restriction. I like sites that will tell you how strong your password is and recommend you make it stronger, but forcing a user to type at least 8 characters, or to require both letters and numbers, etc. is just plain frustrating.

If you need to have a maximum field size (for example for storing in a database) try to make it large enough for anything that people would type out by hand. There's really no such thing as a too-large password field since there's always the potential to use an automated, generated strong password, but 64 to 128 characters would certainly suffice.

chaiguy
Passwords should never be stored in clear text. They should preferably be hashed, and then they are all of the same length.
some
+2  A: 

Remember: When you are storing passwords, all passwords should be encrypted with a one-way algorithm like md5 of sha1. Since these algorithms always yield hexadecimal numbers, you don't need to worry about SQL injections or anything like that.

So, as long as you can md5 or sha1 a character, it should be accepted.

stalepretzel
Actually I'm using SHA-512
PhoenixRedeemer
A: 

Add another vote for "let the user include any and all characters that their interface allows them to enter". I wouldn't even disallow tab or control characters. Your software has the capability to accept arbitrary byte strings and hash them, so accept arbitrary byte strings as passwords. To do otherwise reduces the space which an attacker must search in a brute-force or dictionary attack.

(Of course, even if you do allow everything, 99% of users will still use their pet's name as their password...)

Dave Sherohman
A: 

Eventually you may have to print out the clear password in a confirmlation email sent to your users.

PS: Might consider also encoding problems in the email, if it's not standard ascii (eg. Japanese characters), it's possible that a user will not receive the email in the proper format or simply can't read it on another system due to fonts not being installed.

All this weighs in the "printable" ascii characters range.

faB
If you need to printo ut the clear password in a confirmation e-mail, wouldn't that also mean that you have it stored in plaintext which would be bad?I suppose you could send the email, hash the password, save it in the database and then 'forget' the plain text version but that still seems to defeat the security of having the password in the first place.
GeoffreyF67