user_save() returns FALSE I am trying to use user_save api. i have passed the following object ($user)


object(stdClass)#30 (6) {
  ["name"]=>
  string(12) "user_name"
  ["mail"]=>
  string(22) "myemail@gmail.com"
  ["pass"]=>
  int(1311514302)
  ["created"]=>
  int(1311514302)
  ["status"]=>
  int(1)
  ["roles"]=>
  array(1) {
    [0]=>
    string(10) "OauthUsers"
  }
}


I have used the following function:

$user = new stdClass();
$user-&gt;name = $userdata['name'];
$user-&gt;mail = $userdata['email'];
$user-&gt;pass = time();
$user-&gt;created = time();
$user-&gt;status = 1;
$user-&gt;roles = array('OauthUsers');
user_save($user);


I have tried to drop the "roles" property as well, but in all the cases user_save() returns FALSE.

Do you have any idea of what I am doing wrong?
UPDATED:

If you are going to create new users using user_save() then follow the following syntax.

$user = array(
   'name' =&gt; $userdata['name'],
   'mail' =&gt; $userdata['mail'],
   'init' =&gt; $userdata['mail'],
   'pass' =&gt; user_password(8),
);


Now call the function user_save() and pass the user info as second arg.

$account = user_save(null, $user);
if($account){
     _user_mail_notify('register_admin_created', $account);
}


To update values for already saved user.

$account = user_load(array('uid' =&gt; $userdata['uid']));
$updates = array(
    'pass' =&gt; user_password(),
    'name' =&gt; 'new_name',
    'roles' =&gt; array(
        &lt;rid&gt; =&gt; '&lt;role title&gt;';
    ),
);

user_save($account, $updates);