Answers.Body: <p>You shouldn't need to call changePassword() at all.  Try this:</p>
  
  <pre><code>$user = craft()-&gt;users-&gt;getUserById(6);
  $user-&gt;newPassword = 'mynewpassword123';
  craft()-&gt;users-&gt;saveUser($user);
  </code></pre>
  
  <p>If it's not updating correctly, then there is likely a validation error somewhere.  You can check that with:</p>
  
  <pre><code>$user-&gt;getErrors();
  </code></pre>
  
  <p>Which will return an array of properties that failed validation and their error messages.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-13T20:59:48.840Z
Answers.Text: Is there a way to do this in Craft 3? I can't find anything in the docs
Answers.UserDisplayName: tekstrand
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-17T02:16:44.773Z
Answers.LastActivityDate: 2014-07-17T19:48:36.163Z
Answers.LastEditDate: 2014-07-17T19:48:36.163Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm new to Craft and (attempting to) create a plugin so that I can import existing users from CSV.</p>
  
  <p>I'm referencing this method:</p>
  
  <p><a href="https://docs.craftcms.com/api/v2/craft-usersservice.html#method-changepassword" rel="nofollow noreferrer">https://docs.craftcms.com/api/v2/craft-usersservice.html#method-changepassword</a></p>
  
  <p>In my function, I'm using the following code:</p>
  
  <pre><code>$user = craft()-&gt;users-&gt;getUserById(6);
  $user-&gt;newPassword('mynewpassword123');
  craft()-&gt;users-&gt;changePassword($user);
  craft()-&gt;users-&gt;saveUser($user);
  </code></pre>
  
  <p>Am I completely misunderstanding what this is supposed to do?</p>
  
Tags: <users>
Title: How do I change a user's password programmatically in a plugin?
ThreadText: # How do I change a user's password programmatically in a plugin?
  
  (Asked by: username_0 on 2014-07-17)
  
  I'm new to Craft and (attempting to) create a plugin so that I can import existing users from CSV.
  
  I'm referencing this method:
  
  <https://docs.craftcms.com/api/v2/craft-usersservice.html#method-changepassword>
  
  In my function, I'm using the following code:
  
  ```
  $user = craft()->users->getUserById(6);
  $user->newPassword('mynewpassword123');
  craft()->users->changePassword($user);
  craft()->users->saveUser($user);
  
  ```
  
  Am I completely misunderstanding what this is supposed to do?
  
  **Tags:** users
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-17. Score: 10 | Accepted answer
  
  You shouldn't need to call changePassword() at all. Try this:
  
  ```
  $user = craft()->users->getUserById(6);
  $user->newPassword = 'mynewpassword123';
  craft()->users->saveUser($user);
  
  ```
  
  If it's not updating correctly, then there is likely a validation error somewhere. You can check that with:
  
  ```
  $user->getErrors();
  
  ```
  
  Which will return an array of properties that failed validation and their error messages.
  
  > **Comments:**
  > **username_2**: Is there a way to do this in Craft 3? I can't find anything in the docs  
  
  ---
  
  