Programmatically create a user and assign a role I'm programmatically creating a user with the following code.

$newUser = array(
  'name' =&gt; $mail, 
  'pass' =&gt; 'password',  // note: do not md5 the password
  'mail' =&gt; $mail, 
  'status' =&gt; 1, 
  'init' =&gt; $mail,
  'roles' =&gt; array(5)
);
$user = user_save(null, $newUser);


I have got a role with the role ID equal to 5; when I create the user, in the table "users_roles" there is only a row with the value 0 for the role ID, but if I print the user object with var_dump(), it looks like the roles are created.

What am I doing wrong?
This code worked for me:

$new_user = array(
  'name' =&gt; $name,
  'pass' =&gt; $sifra, // note: do not md5 the password
  'mail' =&gt; $email,
  'status' =&gt; 1,
  'init' =&gt; $email,
  'roles' =&gt; array(
    DRUPAL_AUTHENTICATED_RID =&gt; 'authenticated user',
    3 =&gt; 'custom role',
  ),
);

// The first parameter is sent blank so a new user is created.
user_save('', $new_user);