1

I have implemented a Custom Membership provider. A sample of my code is shown below

public class CustomMembershipProvider : MembershipProvider
{
   public override bool ChangePassword(string username, string oldPassword, string newPassword)
   {
      //logic for changing password
   }

   public override bool ValidateUser(string username, string password)
   {
      //logic for validating user credentials
   }
}

I then registered the above Custom Membership in the web.config file by using

<membership defaultProvider="CustomMembershipProvider">
 <providers>
  <clear/>
   <add name ="CustomMembershipProvider" type="MyApplication.CustomMembershipProvider"/>
 </providers>
</membership>

Now, when I want to authenticate a user, I can call

System.Web.Security.Membership.ValidateUser(username, password);

This works. However, when I want to call the method to change the password, I try calling:

System.Web.Security.Membership.ChangePassword(username, oldPassword, newPassword);

It gives me intellisense and compilation errors saying that System.Web.Security.Membership does not contain the definition for ChangePassword.

How do I link my ChangePassword method to be callable from System.Web.Security.Membership or am I approaching this problem in the wrong way?

2 Answers 2

4

Make sure your Membership provider is well defined:

<membership defaultProvider="CustomMembershipProvider">
  <providers>
    <clear />
    <add connectionStringName="ConnString" enablePasswordReset="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" name="CustomMembershipProvider" type="MyMembershipProvider" />
  </providers>
</membership>

I take it that MyApplication.MyMembershipProvider is your custom Membership class. I would rename to something else to make the web.config easier to read later, so you know what is the class when you see it.

However, what I believe the answer to your problem is, you need to tap into the Provider class within Membership. Since your defined a Custom Provider, you will use this to execute some of your custom changes.

var didChange = System.Web.Security.Membership.Provider.ChangePassword("", "", "");
Sign up to request clarification or add additional context in comments.

4 Comments

The error from Visual Studio is 'System.Web.Security.Membership' does not contain a definition for 'ChangePassword'
no luck. I tried your web.config change along with a rebuild of the entire solution but it still doesnt show up.
Sorry, I jumped the gun to soon on the update! I didn't realize part of my answer didn't post.
The part of your answer in bold fixed my problem. Thanks!
0

If any of the parameter is null in WebSecurity.ChangePassword, it will not call Custom Memembership provider Change Password

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.