This works for me to log in a user. I'm using vBulletin 3.6.8. I pulled the following from a larger module; hopefully I got everything necessary:
PHP Code:
require_once(FORUMPATH.'/includes/init.php');
require_once(FORUMPATH.'/includes/functions.php'); // vbsetcookie, etc.
define('PERMANENT_COOKIE', false);
function fetch_userinfo_from_username($username)
{
// This duplicates the functionality of fetch_userinfo(),
// only with the user name instead of numeric ID as the argument.
// Adapted from verify_authentication() in functions_login.php
global $vbulletin;
$username = strip_blank_ascii($username, ' ');
$vbulletin->userinfo = $vbulletin->db->query_first(
"SELECT userid, usergroupid, membergroupids, infractiongroupids, username, password, salt FROM "
. TABLE_PREFIX . "user WHERE username = '" .
$vbulletin->db->escape_string(htmlspecialchars_uni($username)) ."'");
return $vbulletin->userinfo;
}
// ======== USER LOGIN / LOGOFF ========
function login($username)
{ // password not needed -- assumes you've already authenticated it
global $vbulletin;
fetch_userinfo_from_username($username);
// set cookies
vbsetcookie('userid', $vbulletin->userinfo['userid'],
PERMANENT_COOKIE, true, true);
vbsetcookie('password',
md5($vbulletin->userinfo['password'].COOKIE_SALT),
PERMANENT_COOKIE, true, true);
// create session stuff
process_new_login('', 1, '');
}
function logout()
{
process_logout(); // unsets all cookies and session data
}
This seems to work pretty well. It cleanly logs on and establishes all the session stuff, and cleanly logs off.
I have a much more complete version of the code above, to create, delete, log on, log off, and modify users in
this article.
-A