XF 2.0 External PHP Authentication to Xenforo

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?


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
 
I figured this out from a few posts here.

Code:
$fileDir = '/hackersadvantage/forums';
require($fileDir . '/src/XF.php');
XF::start($fileDir);
$app = \XF::setupApp('XF\App');

$ip = $app->request->getIp();
$loginService = $app->service('XF:User\Login', $username, $ip);

$userValidate = $loginService->validate($password, $error);
if(!$userValidate)
{
  //NOT A GOOD USER or PASSWORD
}
 
How you manage to store the login? I ask because the validator only tells you if the credentials are OK but it doesn't set the cookie or anything else.
 
Last edited:
How you manage to store the login? I ask because the validator only tells you if the credentials are OK but it doesn't set the cookie or anything else.

My Application did not require a cookie, as it does not use any XF pages after authentication.
 
Top Bottom