How do I change a user's password programmatically in a plugin? 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()-&gt;users-&gt;getUserById(6);
$user-&gt;newPassword('mynewpassword123');
craft()-&gt;users-&gt;changePassword($user);
craft()-&gt;users-&gt;saveUser($user);


Am I completely misunderstanding what this is supposed to do?
You shouldn't need to call changePassword() at all.  Try this:

$user = craft()-&gt;users-&gt;getUserById(6);
$user-&gt;newPassword = 'mynewpassword123';
craft()-&gt;users-&gt;saveUser($user);


If it's not updating correctly, then there is likely a validation error somewhere.  You can check that with:

$user-&gt;getErrors();


Which will return an array of properties that failed validation and their error messages.