KozmoK
Active member
Hello,
I am upgrading some php XF1.5 to 2.0
I need to authenticate a user. In 1.5 I used the AutoLoader to access Xenforo_Application object which gave me access to the DB.
Does anyone know a easy way to authenticate a user in XF2.0?
I am upgrading some php XF1.5 to 2.0
I need to authenticate a user. In 1.5 I used the AutoLoader to access Xenforo_Application object which gave me access to the DB.
Does anyone know a easy way to authenticate a user in XF2.0?
Code:
$startTime = microtime(true);
$fileDir = '/BlahBlah/forums';
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);
$Xendb = XenForo_Application::getDb();
$data = $Xendb->fetchOne('
SELECT
auth.data
FROM xf_user_authenticate AS auth
INNER JOIN xf_user AS user ON
(user.user_id = auth.user_id)
WHERE user.username = ?
', $username);
$auth = XenForo_Authentication_Abstract::createDefault();
$auth->setData($data);
$check = $auth->authenticate($username, $password);
if(!$check) // not logged in