Answers.Body: <p>Use <code>newPassword</code> instead:</p>
  
  <pre><code>$user-&gt;newPassword = '123456';
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-27T09:57:14.647Z
Answers.LastActivityDate: 2015-12-27T09:57:14.647Z
Answers.UserDisplayName: Ben Croker
Body: <p>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.</p>
  
  <pre><code>foreach ($docs as $doc) {
  
      $user = new UserModel;
  
      $user-&gt;firstName    = $doc-&gt;FName;
      $user-&gt;lastName     = $doc-&gt;LName;
      $user-&gt;password     = '123456';
      $user-&gt;email        = $doc-&gt;Email;
      $user-&gt;username     = $doc-&gt;Email;
  
      $wasSaved = craft()-&gt;users-&gt;saveUser($user);
  
      if ($wasSaved) {
          $was_assigned = craft()-&gt;userGroups-&gt;assignUserToGroups($user-&gt;id, array(1));
      } else {
          printf("couldn't save: %s", $user-&gt;email);
      }
  
  }
  </code></pre>
  
Tags: <plugin-development><php><password><usermodel>
Title: How do I set the user password when using saveUser service method?
ThreadText: # How do I set the user password when using saveUser service method?
  
  (Asked by: username_0 on 2015-12-27)
  
  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);
      }
  
  }
  
  ```
  
  **Tags:** plugin-development, php, password, usermodel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-27. Score: 4 | Accepted answer
  
  Use `newPassword` instead:
  
  ```
  $user->newPassword = '123456';
  
  ```
  
  
  ---
  
  