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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:59:15+00:00 2026-05-27T09:59:15+00:00

How do I verify in C# that the password contains at least X uppercase

  • 0

How do I verify in C# that the password contains at least X uppercase letters and at least Y numbers, and the entire string is longer than Z?

Thanks.

  • 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-27T09:59:15+00:00Added an answer on May 27, 2026 at 9:59 am

    Password Strength:

    First, I would read up on password strength, and double-check your policy to make sure you were doing the right thing (I couldn’t tell you off hand):

    • http://en.wikipedia.org/wiki/Password_strength
    • https://www.grc.com/haystack.htm
    • http://xkcd.com/936/ (a joke, but good food for thought)

    Then I’d check other questions:

    • Creating a regex to check for a strong password
    • Password strength

    Then I’d get down to business.

    Implementation:

    You could use Linq:

    return password.Length >= z
        && password.Where(char.IsUpper).Count() >= x
        && password.Where(char.IsDigit).Count() >= y
        ;
    

    You could use also regular expressions (which might be a good option to allow you to plug in more complicated validations in the future):

    return password.Length >= z
        && new Regex("[A-Z]").Matches(password).Count >= x
        && new Regex("[0-9]").Matches(password).Count >= y
        ;
    

    Or you could mix and match them.

    If you had to do this multiple times, you could reuse the Regex instances by building a class:

    public class PasswordValidator
    {
        public bool IsValid(string password)
        {
            return password.Length > MinimumLength
                && uppercaseCharacterMatcher.Matches(password).Count
                    >= FewestUppercaseCharactersAllowed
                && digitsMatcher.Matches(password).Count >= FewestDigitsAllowed
                ;
        }
    
        public int FewestUppercaseCharactersAllowed { get; set; }
        public int FewestDigitsAllowed { get; set; }
        public int MinimumLength { get; set; }
    
        private Regex uppercaseCharacterMatcher = new Regex("[A-Z]");
        private Regex digitsMatcher = new Regex("[a-z]");
    }
    
    var validator = new PasswordValidator()
    {
        FewestUppercaseCharactersAllowed = x,
        FewestDigitsAllowed = y,
        MinimumLength = z,
    };
    
    return validator.IsValid(password);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using a regex in Python, how can I verify that a user's password is:
I have a method that sets a property public void SetNetworkCredential(string userName, string password,
I want to add a simple validator to verify that password and confirm password
I am trying to verify that a string is unique within a MySQL column.
I am trying to add one more step that if entered password contains entered
I need to verify that a code generated in one class is same as
How can I verify that passing block is execute correctly ? - (void)locationManager:(CLLocationManager *)manager
How do you 'verify' that a message sent using MSMQ to a private local
I need to verify that a simplified DTD is really a subset of a
How does QA verify that existing product functionality is still working while verifying new

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.