title: How to manually create a user in Moodle?
body: <p>I am trying to create an authentication plugin, but I am having problems when the user does not exist in the moodle database. Therefore I am trying to find a way to manually create a user.</p>
  
  <p>I tried:</p>
  
  <pre><code>$user            = new StdClass();
  $user-&gt;username  = $ucUser;
  $user-&gt;auth      = 'ucauth';
  $user-&gt;firstname = "First";
  $user-&gt;lastname  = "Last";
  $user-&gt;id        = $DB-&gt;insert_record('user', $user);
  </code></pre>
  
  <p>But it didn't work... I got an insert error. What else do I need in the <code>$user</code> object?</p>