Saturday, September 23, 2017

Checking a phpBB login from a new page

Suppose you want to use a phpBB forum's database of users as an authentication method for some other service. It might be possible to figure out the database format and connect directly, but then you miss out on the automatic tracking of failed logins and checking that the account is enabled. So, you might instead create a new PHP script in the existing phpBB site to take advantage of the phpBB infrastructure:
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = 'php';
include('common.php');
include('includes/functions_user.php');
include('phpbb/passwords/manager.php');
$provider_collection = $phpbb_container->get('auth.provider_collection');
$provider = $provider_collection->get_provider();
$result = $provider->login($username, $password);
if ($result['status'] === 3) {
 echo 'Login successful.';
} else {
 echo 'Login failed!';
}

The first three lines are important even if they don't immediately appear to do anything - the included phpBB files check them. Also note that if you're getting the username and password to verify from GET or POST parameters, you'll need to extract them into variables before including the phpBB files because phpBB seems to somehow disable superglobals; attempting to use them results in an error page.

Some of the above script is from this forum post.

No comments:

Post a Comment