MyBB Community Forums

Full Version: Check credentials from custom page?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a game server and would like to make it possible for players to connect/link their forum accounts to the in-game accounts. But I actually see no way of checking if the provided username/password strings are correct? I checked members.php / member_login, but unfortunately to me it's just black magic (the logic and all) ;o

How can I check if the supplied credentials are correct?
You can check if someone is logged into the forum by including global.php in your script then using:
if($mybb->user['uid'])
{
// logged in
}
else
{
// guest
}
but the game server does not have access to the cookies of the user or website database

I tried:
<?php
opcache_reset();
define('IN_MYBB', 1);
require "global.php";
		echo 'admin exists: ';
		if(username_exists("admin") || username_exists("Gamer_Z")) 
			echo("YES"); else echo("NO"); 	
		echo '<br />';
		echo 'juhijhfgvuyjhgfbnguyhjynfbdgfcvytugjhf exists: ';
		if(username_exists("juhijhfgvuyjhgfbnguyhjynfbdgfcvytugjhf")) 
			echo("YES"); else echo("NO"); 
?>
but that does not work when there are no cookies because the functions from the inc/functions_user.php are undefined somehow.
They are undefined because you're not including that file in the above script..
ah okay I fixed it by removing as much code as possible from member.php until it didn't work anymore and I have this now, works nice:

<?php
define("IN_MYBB", 1);

require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/datahandlers/login.php";

$loginhandler = new LoginDataHandler("get");
$user = array('username' => $mybb->get_input('username'),'password' => $mybb->get_input('password'));
$loginhandler->set_data($user);
$validated = $loginhandler->validate_login();

if(!$validated)
{
	echo("F");
}
else if($validated)
{
	echo("S");
}