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?
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?
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.
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 -Identity michael -NewPassword pass123 -OldPassword b