Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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:

http://buildwithcraft.com/docs/apis/usersservice#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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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.

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.