views:

160

answers:

1

Hello,

Is there a way to make ChangePassword control work without Membership provider? Like the same way Login control works through an Authenticate event, could I make this component to use my password changing function and then showing success view without me writing custom provider?

Thanks, Eugene.

EDIT:

Just to clarify after some research through Reflector I came to conclusion that this control is totally useless without MembershipProvider. Every logic bit, like reading configuration file and validating user inputs is outsourced to providers, so you have to write this generic code as well.

This is the list of functions sufficient to make this control work:

public bool ChangePassword(string username, string oldPassword, string newPassword) 
public MembershipUser GetUser(string username, bool userIsOnline)
public int MinRequiredNonAlphanumericCharacters { get; }
public int MinRequiredPasswordLength { get; }

The last two are only used for error message if you return false from ChangePassword function.

+2  A: 

Looking at the .NET 3.5 source through reflector, when the ChangePassword button event gets detected by protected OnBubbleEvent, it calls AttemptChangePassword(). The implementation of that method looks roughly like this:

private void AttemptChangePassword() {
    ...
    this.OnChangingPassword(loginCancelEventArgs);
    if(!e.Cancel) {
        MembershipProvider provider = LoginUtil.GetProvider(this.MembershipProvider);
        ...
}

It looks like you could:

  1. Add a handler to the ChangingPassword event
  2. In that event handler use the control's UserName and NewPassword properties to do your own custom work.
  3. On success either redirect to a new URL or set the cancel flag on the event args and hide the ChangePassword control manually. There does not appear to be an easy way to use the SuccessView with this technique.

So it looks like it's somewhat possible, but the control definitely wasn't designed with this use in mind -- it's pretty well hard-wired to MembershipProvider.

pettys
Thank you. And sorry for the late reply. Your answer made me to look into this problem more deeply.
Eugene Kulabuhov