+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Change Password Programmatically

Change Password Programmatically

3 posts, 1 answered
  1. Jarrod
    Jarrod avatar
    7 posts
    Registered:
    11 May 2012
    07 Jun 2012
    Link to this post
    Using: Sitefinity 5.

    Hi there!

    I am currently working on a User Module whereby it can allow user to change their password when logged on. Its a very classic example of "Old Password, New Password, Retype New Password".

    So there, I need to replace the new password with the existing password. Any suggestion on that?

    By the way, Ive tried the Change Password widget that is available, but it does not seems to be working. I'm seeing empty widget when I published it.

    Thanks alot in advance!
    Jarrod
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    30 Nov 2016
    11 Jun 2012
    Link to this post
    Hello Jarrod,

    Here is the API to change password
    You will have to logged in to execute the API or authenticate a user with permissions to modify users with this API
    // log the admin
              UserManager manager = UserManager.GetManager();
              var objUser = manager.GetUser("admin");
              var validate = SecurityManager.AuthenticateUser(UserManager.GetDefaultProviderName(), "admin", "password", false);
              bool authenticated = validate == UserLoggingReason.Success;

    Change password
    var userManager = UserManager.GetManager("Default");
    // to get old password you must first get the user so you can get its password or other properties
    var getUser = userManager.Getuser(new Guid("2a7339fe-20ee-4a7d-8869-79a4ee4abc45")).Email;
    // you can reset the pass
                var reset = userManager.ResetPassword(new Guid("2a7339fe-20ee-4a7d-8869-79a4ee4abc45"), "123");
                //UserManager.ChangePasswordForUser(userManager, new Guid("2a7339fe-20ee-4a7d-8869-79a4ee4abc45"), "password", "password2", true);
    // of change it with this
                var change = userManager.ChangePassword(new Guid("2a7339fe-20ee-4a7d-8869-79a4ee4abc45"), "password", "password2");
                userManager.SaveChanges();



    Regards,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Nelson
    Nelson avatar
    13 posts
    Registered:
    29 Jul 2015
    21 Oct 2015 in reply to Stanislav Velikov
    Link to this post
    If you tried this code and it didn't worked out, it's the expected behavior. Just replace the "password" string with the reset variable, that actually is the old password after reset, and it will work.
3 posts, 1 answered