7

I am working on forgot password functionality. I use default sitecore user provider. How I can update user password programmatically?

Is it possible to change password by manipulation with object of Sitecore.Security.Accounts.User class?

1
  • Yes you can pass the Name property of the User object into the Membership.GetName(string) method. If that's what you mean. Commented Nov 18, 2016 at 9:54

2 Answers 2

10

As you can't get the old password, you should use the reset functionality:

var user = System.Web.Security.Membership.GetUser(@"domain\username");
var oldPassword = user.ResetPassword();
var newPassword = "Mynewstrongpassword1!";
user.ChangePassword(oldPassword, newPassword);

To change the password, you need to work with the Membership user. But as Dražen mentioned, you can get use the Name property of the Sitecore.Security.Accounts.User object in the GetUser method.

4
  • what type of user?
    – Vlad
    Commented Nov 18, 2016 at 9:34
  • updated code example..
    – Gatogordo
    Commented Nov 18, 2016 at 9:38
  • thanks. can you please also provide answer to my second question?
    – Vlad
    Commented Nov 18, 2016 at 9:42
  • done - although Dražen already did too
    – Gatogordo
    Commented Nov 18, 2016 at 10:10
2

There is a way in case you need to build User Management tools for an internal support team. Let's say an admin needs to reset a password for a Content Author you can take advantage of Sitecore PowerShell Extensions.

Set-UserPassword

Set-UserPassword -Identity michael -NewPassword pass123 -OldPassword b

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.