Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to change user password programmaticallyHow to change user password programmatically
Previous
 
Next
New Post
10/9/2009 8:07 AM
 

In my module there is requirement to change password programetically 

So please guide me how can i change dnn user password in c# code

thanks

 
New Post
10/12/2009 10:48 AM
 

The UserController class within the core API has a ChangePasword method that you can use to change the password for a given user account.


-Mitchel Sellers
Microsoft MVP, ASPInsider, DNN MVP
CEO/Director of Development - IowaComputerGurus Inc.
LinkedIn Profile

Visit mitchelsellers.com for my mostly DNN Blog and support forum.

Visit IowaComputerGurus.com for free DNN Modules, DNN Performance Tips, DNN Consulting Quotes, and DNN Technical Support Services
 
New Post
4/13/2016 2:34 AM
 
This works for me. (DNN 07.04.02)
This is easy way to change password programmatically.

UserInfo userInfo = UserController.GetUserByName(int.Parse(Properties.Resources.PortalId), "testuser");
UserController.ChangePassword(userInfo, UserController.ResetPassword(userInfo, "").ToString(), "newpassword");
 
New Post
11/9/2018 9:53 PM
 

DotNetNuke modules required an option to reset/change a users password. I set of trying all sorts of things as the ChangePassword function on the UserController required me to pass the old password which I did not know how to get.

After some more looking around I found that you can get the old password by using the UserController.GetPassword, I finished off my ChangePassword function and here it is below.

public enum PwdAction
{
    ChangePassword,
    ChangePasswordForceChange
}
 
public bool ChangePassword(int portalID, string Username, string newPassword, PwdAction action)
{
    string sOldPassword;
    bool bChangePassword;
    UserInfo oUserInfo = UserController.GetUserByName(portalId, UserName);
    //Get the older password. This is required to change the password
    sOldPassword = UserController.GetPassword(ref oUserInfo, "");
    if (oUserInfo != null)
    {
        switch (action)
        {
            case Utilities.PwdAction.ChangePassword:
                bChangePassword = UserController.ChangePassword(oUserInfo, sOldPassword, newPassword);
                break;
            case Utilities.PwdAction.ChangePasswordForceChange:
                bChangePassword = UserController.ChangePassword(oUserInfo, sOldPassword, newPassword);
                if (bChangePassword)
                {
                    // After changing the password, make sure user is forced to change the password to a new password
                    oUserInfo.Membership.UpdatePassword = true;
                    UserController.UpdateUser(oUserInfo.PortalID, oUserInfo);
                }
                break;
            default:
                Exception exc = new Exception(String.Format("Unknown action '{0}'", PwdAction.ToString()));
                Exceptions.LogException(exc);
                break;
        }
    }
    return bChangePassword;
}
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to change user password programmaticallyHow to change user password programmatically


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out