The documentation for MembershipProvider.OnValidatingPassword only states that it raises the ValidatingPassword event if the handler is registered, and not that it actually verifies the password.
A search in Reflector confirms this:
protected virtual void OnValidatingPassword(ValidatePasswordEventArgs e) { if (this._EventHandler != null) { this._EventHandler(this, e); } }
This is confusing, but I believe the intention is that it provides a hook for external logic to participate in password verification; A user provider will still have to write its own validation logic.
If you look at the source code for the SQL Membership Provider (download Provider Toolkit Examples> , you will see that it includes logic to verify the password and also calls OnValidatingPassword . The following code applies to 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 OnValidatingPassword and that this seems to imply that it handles password verification, rather than raising an event so that other code checks the password. For what it's worth, I understand the confusion - it would probably be clearer if this method were called RaiseValidatingPasswordEvent .
In any case, you can check the Event Design rules for .NET 4. About halfway down you will find the following:
Use a secure virtual method to enhance each event.
The name of the protected virtual method must be the same as the name of the event with the On prefix. For example, a secure virtual method for an event named "TimeChanged" is called "OnTimeChanged".
Jeff ogata
source share