login programmatically with remember me feature
This is how I accomplished the remember me feature. Since I didn't find any specific resources on this matter, the proposed solution may or may not be optimal and correct, although it works fine.

You use the following code to login a user programmatically: 

$user = user_load($uid);
$login_array = array ('name' =&gt; $user_first_query-&gt;name);
user_login_finalize($login_array);


After that you have to decide whether to persist the login or not using the provided check box in the login form:

//at this point we need to persist the login by saving the user again
//with the remember_me data. But doing so, resets the user picture.
//So we need to preserve it somehow.
$user_picture_id = $user-&gt;picture;
if($_POST['remember_me']) {
    user_save($user, array('data' =&gt; array('remember_me' =&gt; (int)$_POST['remember_me'])));
}
else {
    unset($user-&gt;data['remember_me']);
    user_save($user, array());
}

//restore the user picture id
db_update('users')
    -&gt;fields(array(
         'picture' =&gt; $user_picture_id,
    ))
    -&gt;condition('uid', $uid)
    -&gt;execute();


For the part where I have done unset($user-&gt;data['remember_me']); I have made sure that the rememeber_me data does not exist from a previous login. I think this should be done in the modulename_user_presave() hook but I couldn't implement it there.

Remember that since the main question is how to persist a user login, I have not provided a full login procedure, for example you should authenticate the user's credentials using the user_authenticate() function.