Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8418
  • Last Modified:

Change password in code using asp.net membership

I need a quick example of how to change membership user's password in code.  I cannot use the changepassword control
0
mugsey
Asked:
mugsey
1 Solution
 
bungHocCommented:
Please tell me why you can't use ChangePassword control? AFAIK, that's the simple way to do it.
0
 
ventaurCommented:
You'll need to know the old password for this to work:

using System.Web.Security;
...

string UserName = User.Identity.Name; // or some other source for the user name
MembershipUser UserToChange = Membership.GetUser(UserName);
UserToChange.ChangePassword(OldPassword, NewPassword);


-----------------------
Regards,
-Matt
0
 
Mayank_AgarwalCommented:
Thansk this did help me a lot

Are you able to tell me why does the ChangePasswrod control gives "password incorrect or ........" error even if it has successfully changed the password?

Mayank
0
 
mugseyAuthor Commented:
Hi

It was my web.config was not configured correctly
0
 
Mayank_AgarwalCommented:
Can you please clarify what part was wrong with Web.config
here is asnippet of mine
            <membership defaultProvider="CustomizedMembershipProvider">
                  <providers>
                        <add name="CustomizedMembershipProvider" type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="myconnString" applicationName="/"
             requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="3"
             enablePasswordReset="true"
             enablePasswordRetrieval="false"/>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now