tags:

views:

145

answers:

2

Dear all, I want an auto username suggestion if a username is already used ,using mysql procedure

A: 

I use jquery for username suggestion. Examples: http://remysharp.com/wp-content/uploads/2007/12/tagging.php http://fromvega.com/wordpress/2007/05/08/auto-complete-field-with-jquery-code-explained/

TeknoSeyfo
A: 

By User Name suggestion, do you mean you want a type-ahead autocomplete on a login form (i.e. once you type a few characters of your user name, the application will show all user names matching the supplied user name), or do you you mean a suggestion box that provides potential alternate user names if new user supplies an existing user name?

If you're looking for the first, I would recommend avoiding this. By providing a server-side autocomplete for user names, you are providing a simple way to access the names of all users in your system and reducing security (as people trying to access your site without permission will only need to determine a password instead of a user name and password).

If it's the second, one common approach is to append numbers at the end of an existing user name to provide a user name that does not exist. I would recommend doing this in a combination of MySQL and whatever server-side language you are using.

First, get all user names that start with the user name that was supplied (and already exists):

SELECT user_name FROM users where user_name LIKE @userName + '%'

Then, in your server side language, do the following (pseudo-code)

let user = username supplied (already exists)
let recordset = recordset from db call (above)    

i = 0
alternateCount = 0
alternatesFound = new string[5]
while (alternateCount < 5 And i < 100)
    potentialName = user + i
    if (recordset does not contain potentialName)
       alternatesFound[alternateCount] = potentialName
       alternateCount++
    end if
end while

What this does is attempts to insert sucessive numbers (1,2,3) etc. to the supplied user name until it finds 5 cases where the user name is unique. It also does a maximum of 100 iterations in case user1 - user99 is taken (you could increase this but a limit isn't a bad idea.

Ryan Brunner
Thanks Ryan For your support,can u please tell me the logic of handling all this in a stored procedure of mysql.Thanks
kiks
You're going to have to do some of your own coding, @kiks.
ceejayoz