Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
Yes you can pass the Name property of the User object into the Membership.GetName(string) method. If that's what you mean. – Dražen Janjiček Nov 18 '16 at 9:54
up vote 6 down vote accepted

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

var user = System.Web.Security.Membership.GetUser(@"domain\username")
string oldPassword = user.ResetPassword();
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.

share|improve this answer
    
what type of user? – Vlad Nov 18 '16 at 9:34
    
updated code example.. – Gatogordo Nov 18 '16 at 9:38
    
thanks. can you please also provide answer to my second question? – Vlad Nov 18 '16 at 9:42
    
done - although Dražen already did too – Gatogordo Nov 18 '16 at 10:10

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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