Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8605911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:57:49+00:00 2026-06-12T02:57:49+00:00

I am stuck on a situation where i am trying to generate password for

  • 0

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 –

if (entities.Users.Any(a => a.LastName == tbLname.Text && a.FirstName.StartsWith(fname))) 
 username = (tbLname.Text + tbFname.Text.Substring(0,2)).ToLower();

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:57:50+00:00Added an answer on June 12, 2026 at 2:57 am

    There is more information needed from the OP on this if the application wants to avoid bugs, but, in the meantime this should solve the question at hand.

    //Store the first possible name.
    var possibleUsername = string.Format("{0}{1}", tbLname.Text, tbFname.Text.Substring(0,1))
    
    //Don't hit the database N times, instead get all the possible names in one shot.
    var existingUsers = entities.Users.Where(u => u.Username.StartsWith(possibleUsername)).ToList();
    
    //Find the first possible open username.
    if (existingUsers.Count == 0) {
        //Create the user since the username is open.
    } else {
        //Iterate through all the possible usernames and create it when a spot is open.
        for(var i = 1; i < existingUsers.Count; i++) {
            if (existingUsers.FirstOrDefault(u => u.Username == string.Format("{0}{1}", tbLname.Text, tbFname.Text.Substring(0, i))) == null) {
                //Create the user since the user name is open.
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck in a situation from which I am finding no solution. Let
I'm stuck with a LINQ group by situation trying to solve it without using
I'm trying to eliminate memory leaks from my project, but i'm stuck in 2
I'm basically stuck in a situation where I need a bunch of div's with
I'm using ASP.NET MVC 2 and stuck with the situation when needed to store
I am new to iPhone programming, and stuck in a situation. The situation is
I just stuck in a very simple situation bt couldnt help myself.My question is
I'm trying to use Microsoft Solver Foundation 2 to solve a fairly complicated situation,
I'm trying to connect to an API, authenticate a user and then view the
I'm stuck in a situation where I believe I need to know the name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.