tags:

views:

610

answers:

4

So I have a system that is going to allow specific users the ability to create new user accounts but, for several reasons, they cannot get a listing of all users on the system. That could make creating new user names difficult (if they can't see a list of used names)

Are there any standard ways of creating a user name out of a person's first and last name?

Right now the system tries to default using first initial last name...but what if that's a taken name? Is there an easy way of creating this new user name without making the person try again and again? (And I'd rather not end up with jsmith1234)

I have PHP, jquery, mySQL at my disposal

+6  A: 

Since names aren't unique either, I can't see how that would work. Basically you have to be able to handle collision, which also lets people pick their own usernames.

My advice though is don't submit the whole form and then return it to the user "username not available", usually with the password fields cleared (so you have to type those in with every attempt). This is one of my biggest pet peeves with registration processes.

Use AJAX to check availability. Either with an explicit "Check availability" button or when the text field loses focus (blur event) you go check yourself.

cletus
This is my preferred method as well. Generally you don't even need specific error messages. I use "That username is unavailable" for duplicate names, offensive names, too short/long, etc. As long as the requirements are clear, the user will likely not think twice about an unavailable username, and move on to thinking of another one.
zombat
Agreed, they don't need to see the whole list but you could still let them choose something. Also, make sure you have a way to lookup your own username. Sometimes people forget if they've registered at your site already.
AndyMcKenna
That is the standard way we do things normally. I'm trying to make this as easy as possible. Thanks for the answer
Jason
+9  A: 

You could always use the person's email address in authentication instead of a traditional username. If other people can't see the username anyway this would be the best approach.

Kane Wallmann
PLEASE USE THE EMAIL ADDRESS! Can 8 other people vote this up really quickly. I really hate sites that ask for a name then put arbitrary quasi-random restrictions on it (must have a number, must be only letters, must have a number and a symbol). Chase just did this to me when they butt-raped all WAMU's adequate, usable software and I'm tempted to leave over it (Okay, so I'm being a bit extreme, but just please allow and suggest an email address instead of user name)
Bill K
@Bill K - I've never run into a site that forces non-alphanumeric restrictions on a username, generally that's reserved for passwords. Also, there's situations where an email address isn't ideal as a unique username (e.g. naming a character for a web game).
zombat
@zombat that's true but as I noted he said that other people won't see the username so really there's no reason not to use an email.
Kane Wallmann
Thanks, that's really what I need to do. Easy and straightforward
Jason
+3  A: 

Hey Jason. I'd suggest the following. First create an algorithm that gives possible usernames, given an first name and last name.

e.g.

$foo->genPossibleUserNames('Dave', 'Smith');
could return

  • dsmith (first initial, lastname)
  • dasmith (first 2 initials . lastname)
  • davesmith (first name . lastname)
  • dave.smith (firstname '.' lastname)
  • davsmith (first 3 initials . lastname)

You would order this array of possible usernames by your personal preferences of course. You would then check the database for uniqueness of these names, and provide them as a list of options to your user.

Of course if your user base grows large enough, having dsmith1 is inevitable, but at least this way it encourages users to choose something more preferable first.

hobodave
A: 

I think you are eventually going to end up with jsmith123, but you could just come up with some kind of algorithm like.

Person: John Smith
Try1: johnsmith
Try2: smithjohn
Try3: jsmith
Try4: johns
Try5: johnsm
Try6: johnsmi

And so on. If you eventually don't get a unique name you will have to revert to numbers, but you should get 98% of names without that.

Craig