Strange behavior while assigning the role programmatically I used this code to set role to a user :

    user_external_login_register($form_state['values']['name'], 'beneficiaire');
    $account = user_external_load($form_state['values']['name']);
    $form_state['uid'] = $account-&gt;uid;
    $account-&gt;roles[]= 3;
    user_save($account);


My user is weel registered as admin, but if I logout and login, my user has an empty role in addition of the administrator.

Replacing 3 by administrator does not fix.

Do you have an idea of what's going on?

Thanks.
This is the roles element in $user object ( $user->roles )

roles =&gt; array(
  2 =&gt; "authenticated user",
  4 =&gt; "Site Administrator",
  6 =&gt; "Author",
),


You must set the user role like:

$user-&gt;roles[ROLE_ID] = 'ROLE_NAME'