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

The Archive Base Latest Questions

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

I am working to implement a custom Membership Provider for my .net application. I

  • 0

I am working to implement a custom Membership Provider for my .net application. I have set up the configuration for a minimum number of characters and non-alphanumeric characters, but it seems to let passwords through anyway, even when they break the rules.

OnValidatingPassword is a virtual method. The example from Microsoft does not override the method.

This question grapples with the same problem, but the author gave up on getting the answer to his question and simply overrode the function. This answer states that one does not have to override the function to have it work.

Does the base function not do anything? When I override OnValidatePassword, and simply call the base class, my function gets hit, but it never rejects my too-simple passwords.

Code sample (with a custom CreateUser function)

protected override void OnValidatingPassword(ValidatePasswordEventArgs e)
        {                        
             base.OnValidatingPassword(e);
        }
        //
        // MembershipProvider.CreateUser
        //
        public MembershipUser CreateUser(string username, string password, string globalIdentifier, string firstName, string lastName, 
            string birthDate, object providerUserKey, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }
  • 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-26T02:59:15+00:00Added an answer on May 26, 2026 at 2:59 am

    The documentation for MembershipProvider.OnValidatingPassword only states that that it raises the ValidatingPassword event if a handler is registered, not that it actually validates the password.

    Looking at the method in Reflector confirms this:

    protected virtual void OnValidatingPassword(ValidatePasswordEventArgs e)
    {
        if (this._EventHandler != null)
        {
            this._EventHandler(this, e);
        }
    }
    

    It is confusing, but I believe the intent is that this provides a hook for external logic to participate in password validation; A custom provider would still need to write its own validation logic.

    If you take a look at the source code for the SQL Membership Provider (download the Provider Toolkit Samples), you’ll see that it includes logic to validate the password, and also calls OnValidatingPassword. The following code is from the CreateUser method:

    if( password.Length < MinRequiredPasswordLength )
    {
        status = MembershipCreateStatus.InvalidPassword;
        return null;
    }
    
    int count = 0;
    
    for( int i = 0; i < password.Length; i++ )
    {
        if( !char.IsLetterOrDigit( password, i ) )
        {
            count++;
        }
    }
    
    if( count < MinRequiredNonAlphanumericCharacters )
    {
        status = MembershipCreateStatus.InvalidPassword;
        return null;
    }
    
    if( PasswordStrengthRegularExpression.Length > 0 )
    {
        if( !Regex.IsMatch( password, PasswordStrengthRegularExpression ) )
        {
            status = MembershipCreateStatus.InvalidPassword;
            return null;
        }
    }
    
    ValidatePasswordEventArgs e = new ValidatePasswordEventArgs( username, password, true );
    OnValidatingPassword( e );
    
    if( e.Cancel )
    {
        status = MembershipCreateStatus.InvalidPassword;
        return null;
    }
    

    Edit

    I think part of the confusion is based on the name of OnValidatingPassword, and that it seems to imply that it is handling password validation, rather than raising an event to let other code validate the password. For what it’s worth, I understand the confusion – it would probably be clearer if the method had been named RaiseValidatingPasswordEvent.

    In any case, you can check the Event Design guidelines for .NET 4. About halfway down the page, you’ll find this:

    Do use a protected virtual method to raise each event.

    The name of the protected virtual method should be the
    same as the event name prefixed with On. For example, the protected
    virtual method for an event named “TimeChanged” is named
    “OnTimeChanged”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a custom membership provider using LINQ to SQL. When I added
I'm working on a custom Cortex-M3-based device and I need to implement in-application programming
I am working on an ASP.net Ajax custom control, I have tried to derive
I am using custom attributes to implement theme switching in my application. I have
My scenario is this: I have a custom RavenDB membership provider that is implemented
I have a custom auth provider working against a REST API and now want
I am working on implementing a custom membership provider that works against an existing
Working on a project at the moment and we have to implement soft deletion
I'm working on a thread library which implement user level threads (i have something
We've been working on web application where in we need to implement traditional web-apps

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.