technique to iterate through the FirstName, LastName to create username

Jake02

New Member
I am stuck on a situation where i am trying to generate password for a given username. I am creating a username from the user's input through textbox for FirstName and LastName, by the user's lastname + first letter of the firstname. For e.x., If the user's First name is 'Ronald' and the last name is 'Test', i add the username in the database as 'Testr'. But if i had the same last name for another user and the firstname begins with the same name as existing user in the database, i add the first 2 letters of the firstname like this -\[code\]if (entities.Users.Any(a => a.LastName == tbLname.Text && a.FirstName.StartsWith(fname))) username = (tbLname.Text + tbFname.Text.Substring(0,2)).ToLower();\[/code\]Now the issue is, this works only if the first 2 letters match the first name. What if i had 3 or even 4 matching the first names? I dont have a clue how to check for the remaining characters to have a unique username.Any idea on how to achieve this ? Thanks in advance.
 
Back
Top