4

I am saving users from an external source and able to create them in the Craft db as users. However, each user's password is set to null despite setting it on the user model prior to saving it. Is there a way to handle setting passwords during user creation? I am not requiring email verification.

foreach ($docs as $doc) {

    $user = new UserModel;

    $user->firstName    = $doc->FName;
    $user->lastName     = $doc->LName;
    $user->password     = '123456';
    $user->email        = $doc->Email;
    $user->username     = $doc->Email;

    $wasSaved = craft()->users->saveUser($user);

    if ($wasSaved) {
        $was_assigned = craft()->userGroups->assignUserToGroups($user->id, array(1));
    } else {
        printf("couldn't save: %s", $user->email);
    }

}
4

Use newPassword instead:

$user->newPassword = '123456';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.