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

  • SEARCH
  • Home
  • 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 6885065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:35:17+00:00 2026-05-27T05:35:17+00:00

I am having a little problem here. Here is my situation: I am typing

  • 0

I am having a little problem here. Here is my situation:

I am typing user name: tester (valid user name; avoiding all checks) and then type password: testerr (valid password; avoiding all checks). Problem is that I am checking for the same inputs. And in my code when both inputs are the same I will see a notification. Now, when I type tester as user name and password I get the error, but when I add additional character to my password ‘testerr’ I am making password valid, but user name is checked as invalid saying that both are still the same and making my validation impossible.

How can avoid this? I was thinking of rechecking user name field from field 2, but I’m not sure how.

bool passIsValid, userIsValid;

public AuthenticationWindow()
{
    InitializeComponent();

    // Creating TextChanged events which till validate input fields.
    txtUserName.TextChanged += new EventHandler(txtUserName_TextChanged);
    txtPassword.TextChanged += new EventHandler(txtPassword_TextChanged);
}

private void txtUserName_TextChanged(object sender, EventArgs e)
{
    // Checking for empty user name field.
    if (string.IsNullOrEmpty(txtUserName.Text))
    {
        lblMessageUser.Text = "User Name field cannot be empty!";
        lblMessageUser.ForeColor = Color.IndianRed;
        btnAuthenticate.Enabled = false;
        userIsValid = false;
    }
    // Making sure that user name is at least 6 characters long.
    else if (txtUserName.Text.Length < 6)
    {
        lblMessageUser.Text = "User Name field must be at least 6 characters long!";
        lblMessageUser.ForeColor = Color.IndianRed;
        btnAuthenticate.Enabled = false;
        userIsValid = false;
    }
    // Checking for user name made of same repeating character.
    // Invalid example: 'aaaaaa'
    else if (!txtUserName.Text.Distinct().Skip(1).Any())
    {
        lblMessageUser.Text = "User Name cannot be made of repeating the same characters!";
        lblMessageUser.ForeColor = Color.IndianRed;
        btnAuthenticate.Enabled = false;
        userIsValid = false;
    }
    // Making sure that password and user name aren't the same.
    else if (txtUserName.Text == txtPassword.Text)
    {
        lblMessageUser.Text = "User Name and Password can not be the same!";
        lblMessagePass.Text = "User Name and Password can not be the same!";
        lblMessageUser.ForeColor = Color.IndianRed;
        lblMessagePass.ForeColor = Color.IndianRed;
        btnAuthenticate.Enabled = false;
        userIsValid = false;
        passIsValid = false;
    }
    // If all other checks aren't trigered; enable authentication.
    else
    {
        lblMessageUser.Text = "User Name is valid.";
        lblMessageUser.ForeColor = Color.Green;

        userIsValid = true;

        if (passIsValid && userIsValid)
        {
            btnAuthenticate.Enabled = true;
        }
    }
}

private void txtPassword_TextChanged(object sender, EventArgs e)
{
    // Checking for Null or Empty string in password field.
    if (string.IsNullOrEmpty(txtPassword.Text))
    {
        lblMessagePass.Text = "Password field cannot be empty!";
        lblMessagePass.ForeColor = Color.IndianRed;
        btnAuthenticate.Enabled = false;
        passIsValid = false;
    }
    // Making sure that password is at least 6 characters long.
    else if (txtPassword.Text.Length < 6)
    {
        lblMessagePass.Text = "Password field must be at least 6 characters long!";
        lblMessagePass.ForeColor = Color.IndianRed;
        btnAuthenticate.Enabled = false;
        passIsValid = false;
    }
    // Checking for password made of same repeating character.
    // Invalid example: 'aaaaaa'
    else if (!txtPassword.Text.Distinct().Skip(1).Any())
    {
        lblMessagePass.Text = "Password cannot be made of repeating the same characters!";
        lblMessagePass.ForeColor = Color.IndianRed;
        btnAuthenticate.Enabled = false;
        passIsValid = false;
    }
    // Making sure that user name and password are not the same.
    // Security measure.
    else if (txtUserName.Text == txtPassword.Text)
    {
        lblMessageUser.Text = "User Name and Password can not be the same!";
        lblMessagePass.Text = "User Name and Password can not be the same!";
        lblMessageUser.ForeColor = Color.IndianRed;
        lblMessagePass.ForeColor = Color.IndianRed;
        btnAuthenticate.Enabled = false;
        userIsValid = false;
        passIsValid = false;
    }
    // If all other checks aren't trigered; enable authentication.
    else
    {
        lblMessagePass.Text = "Password is valid.";
        lblMessagePass.ForeColor = Color.Green;

        passIsValid = true;

        if (passIsValid && userIsValid)
        {
            btnAuthenticate.Enabled = true;
        }
    }
}
  • 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-05-27T05:35:18+00:00Added an answer on May 27, 2026 at 5:35 am

    You can merge your both events into one, then the user sees all errors and your check could be successful.

    bool passIsValid, userIsValid;
    
    public AuthenticationWindow()
    {
        InitializeComponent();
    
        // Creating TextChanged events which till validate input fields.
        txtUserName.TextChanged += new EventHandler(txtCheck_TextChanged);
        txtPassword.TextChanged += new EventHandler(txtCheck_TextChanged);
    }
    
    private void txtCheck_TextChanged(object sender, EventArgs e)
    {
        // Checking for empty user name field.
        if (string.IsNullOrEmpty(txtUserName.Text))
        {
            lblMessageUser.Text = "User Name field cannot be empty!";
            lblMessageUser.ForeColor = Color.IndianRed;
            btnAuthenticate.Enabled = false;
            userIsValid = false;
        }
        // Making sure that user name is at least 6 characters long.
        else if (txtUserName.Text.Length < 6)
        {
            lblMessageUser.Text = "User Name field must be at least 6 characters long!";
            lblMessageUser.ForeColor = Color.IndianRed;
            btnAuthenticate.Enabled = false;
            userIsValid = false;
        }
        // Checking for user name made of same repeating character.
        // Invalid example: 'aaaaaa'
        else if (!txtUserName.Text.Distinct().Skip(1).Any())
        {
            lblMessageUser.Text = "User Name cannot be made of repeating the same characters!";
            lblMessageUser.ForeColor = Color.IndianRed;
            btnAuthenticate.Enabled = false;
            userIsValid = false;
        }
        else
        {
            userIsValid = true;
            lblMessageUser.Text = "Password is valid.";
            lblMessageUser.ForeColor = Color.Green;
        }
    
        // Checking for Null or Empty string in password field.
        if (string.IsNullOrEmpty(txtPassword.Text))
        {
            lblMessagePass.Text = "Password field cannot be empty!";
            lblMessagePass.ForeColor = Color.IndianRed;
            btnAuthenticate.Enabled = false;
            passIsValid = false;
        }
        // Making sure that password is at least 6 characters long.
        else if (txtPassword.Text.Length < 6)
        {
            lblMessagePass.Text = "Password field must be at least 6 characters long!";
            lblMessagePass.ForeColor = Color.IndianRed;
            btnAuthenticate.Enabled = false;
            passIsValid = false;
        }
        // Checking for password made of same repeating character.
        // Invalid example: 'aaaaaa'
        else if (!txtPassword.Text.Distinct().Skip(1).Any())
        {
            lblMessagePass.Text = "Password cannot be made of repeating the same characters!";
            lblMessagePass.ForeColor = Color.IndianRed;
            btnAuthenticate.Enabled = false;
            passIsValid = false;
        }
        else
        {
            passIsValid = true;
            lblMessagePass.Text = "Password is valid.";
            lblMessagePass.ForeColor = Color.Green;
        }
    
        // Making sure that user name and password are not the same.
        // Security measure.
        if (txtUserName.Text == txtPassword.Text)
        {
            lblMessageUser.Text = "User Name and Password can not be the same!";
            lblMessagePass.Text = "User Name and Password can not be the same!";
            lblMessageUser.ForeColor = Color.IndianRed;
            lblMessagePass.ForeColor = Color.IndianRed;
            btnAuthenticate.Enabled = false;
            userIsValid = false;
            passIsValid = false;
        }
    
        // If all other checks aren't trigered; enable authentication.
        if (passIsValid && userIsValid)
        {
            btnAuthenticate.Enabled = true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a little bit of trouble understanding what the problem is here. I
I'm having a little problem here! I have discovered the following as being the
Im having a little problem with classes. Here is some of my code: //GameMap.h
today i'm having a little problem, that probably is nothing for pros here :)
i'm having a little problem. I'm working on a wordpress template which lists all
I'm having a little problem here, I want to use next() but I want
I'm having a little problem with this setup here I have a list of
I'm having a little problem with using conditionally evaluated expression in jsf/a4j Here's my
I'm having a little bit of a problem here, whenever I use an action
I'm having a little problem and I don't see why, it's easy to go

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.