How to Change User's Password with Sitefinity API

by Vesselin Vassilev Mar 7, 2019, 10:18 AM

Normally you need to know the old password of the user in order to change it via the API. This blog post shows you how you can do it without knowing it.

Scenario: you want to change (not reset) a user's password using the Sitefinity API, but all methods (UserManager.ChangePassword() and UserManager.ChangePasswordForUser()) require that you know and provide the old password as a parameter. That's not always possible, so this blog will show you how to do it. 

The trick here is that you first need to *reset* the user's password using the UserManager.ResetPassword() method - it does not require knowing of the old password, it simply generates a new one and assigns it to the user. So, this method will give you the new password which you can then pass to the UserManager.ChangePassword() method as the existing one. 

The below code assumes that you know the Id of the user, e.g. by Querying the user by first name.