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 6888725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:03:48+00:00 2026-05-27T06:03:48+00:00

I ma using this article which explains how to use password strength validator. The

  • 0

I ma using this article which explains how to use password strength validator.

The problem is that it doesn’t seem to check and count each step while typing a password. It seems like it checks for only more than 6 and more than 10 characters giving me maximum count of 3.

Might the problem be because I am using TextChanged function?

Here is my code from validator:

enum PasswordScore
{
    Blank = 0,
    VeryWeak = 1,
    Weak = 2,
    Medium = 3,
    Strong = 4,
    VeryStrong = 5
}

private static PasswordScore CheckStrength(string password)
{
    int score = 1;

        if (password.Length < 1)
            return PasswordScore.Blank;
        if (password.Length < 4)
            return PasswordScore.VeryWeak;

        if (password.Length >= 6)
        score++;
        if (password.Length >= 10)
            score++;
        if (Regex.IsMatch(password, @"/\d+/", RegexOptions.ECMAScript))
            score++;
    if (Regex.IsMatch(password, @"/[a-z]/", RegexOptions.ECMAScript) &&
        Regex.IsMatch(password, @"/[A-Z]/", RegexOptions.ECMAScript))
            score++;
    if (Regex.IsMatch(password, @"/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/",
        RegexOptions.ECMAScript))
            score++;

        return (PasswordScore)score;
}

Here is my TextChanged function (note: the code where I am passing a value to checking method is in the second to the last line of this code):

    // Checking user input for variety of things.
    // This is intended as security measure.
    private void validateInput(object sender, EventArgs e)
    {
        // ======== Start validating Password field ========
        // 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 user name 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 input 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)
        {
            lblMessagePass.Text = "User Name and Password can not be the same!";
            lblMessagePass.ForeColor = Color.IndianRed;
            btnAuthenticate.Enabled = 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;
            }
        }
        // ======== End validating Password field ========

        lblStrength.Text = CheckStrength(txtPassword.Text).ToString();
    }
  • 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-27T06:03:48+00:00Added an answer on May 27, 2026 at 6:03 am

    You don’t need the slashes (/) in your Regex patterns, or the commas in the last one.
    Try this:

    if (Regex.IsMatch(password, @"\d+", RegexOptions.ECMAScript))
        score++;
    if (Regex.IsMatch(password, @"[a-z]", RegexOptions.ECMAScript) &&
        Regex.IsMatch(password, @"[A-Z]", RegexOptions.ECMAScript))
        score++;
    if (Regex.IsMatch(password, @".[!@#\$%\^&\*\?_~\-£\(\)]", RegexOptions.ECMAScript))
        score++; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading this article: Using Interfaces in C++ I have decided to use the
I'm using this article to start a process on a remote machine using WMI.
I wrote my code using this article at msdn as a primary helper My
i m using this article http://blogs.msdn.com/delay/archive/2009/09/23/if-it-walks-like-a-duck-and-talks-like-a-duck-it-must-be-a-treegrid-a-simple-xaml-only-treegrid-ui-for-wpf.aspx to have hierarchical data... i am having treeview
When I saw this article about using a python-like sintax (indentation based, without curly
Based on this article , it seems like SO is using Javascript OpenID Selector
LearnWPF.com posted this article about converting bitmap images to XAML and using them in
I want to implement an apperance as this article mentioned using nested ListView control.
First let me say I have read this useful article thoroughly and am using
I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using

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.