Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trimming whitespace from usernames and passwords [closed]

The iPad application I'm working on requires that the user provide a username and password that are authenticated against a server before they can enter the application proper. I'm considering making a subtle change so that whitespace at the start and end of the username and password are silently ignored.

Good idea? Bad idea? Reasons for your position?

This has come about after I demonstrated the product to a customer today and struggled to log in. After three attempts I finally realised that I'd somehow managed to put a space before my username, and of course, that didn't match any username on the server. There's a very, very subtle difference in width with an additional space at the start of a text field on the iPad, given that the field border is spaced away from the first character anyway, and it took me some time to notice.

like image 781
Andrew Avatar asked Mar 30 '12 06:03

Andrew


People also ask

Should passwords be trimmed?

You should not trim the password. If you do not want to accept passwords with spaces then a password containing spaces should not be accepted.

Should whitespace be allowed in password?

Absolutely! Using spaces in passwords is an excellent idea, because it significantly improves the security (strength) of your passwords. It helps to protect your accounts from attackers who might be trying to guess your passwords, crack them, or employ brute forcing in order to compromise your accounts.

Why do usernames not allow spaces?

Usernames typically don't contain spaces, so allowing users to type in an invalid input and silently removing the space is overly presumptuous for the UX. It's better to detect the interstitial space and inform the user (e.g. Usernames can't contain spaces ) so they can check the username again.


1 Answers

I think that it is a good practice to trim the whitespaces, since they are usually considered invalid username/password symbols (users can miss them very easily, especially if they use more than one).

NSString *trimmedString = [myString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
like image 112
Alexander Avatar answered Nov 16 '22 00:11

Alexander