MyBB Community Forums

Full Version: Question about the login system
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello there Smile

I want to make a login form in my website that uses the same users table (in the DB) in my MyBB forum.
I mean that I want to give to the users the option to log in into their account from the site, with the same username and password.
And now is the question:
The encoding for the password, what should it be?
something like that:
<?php
$password = md5($_POST['password']); // OR OTHER ENCODING
if($password == $user['password'])
.....

?>
Pay attention to the md5 encoding in the PHP Code above.

Thanks Smile
The easiest way is if you include the MyBB core in your script.
chdir('forum'); // if your forum is in a different directory, change it here

define('IN_MYBB', 1);
require_once './global.php';

$username = $mybb->input['username'];
$password = $mybb->input['password'];

$user = validate_password_from_username($username, $password);
if($user !== false)
{
    // user is logged in
}
else
{
    // bad password
}

However, if you don't want to include the MyBB core, you need to do a bit more work.
// assume that you already have set up the MySQL database connection

$username = mysql_real_escape_string($_POST['username']);
$password = $_POST['password'];

$query = mysql_query("SELECT * FROM mybb_users WHERE username='{$username}'");
if(mysql_num_rows($query) == 0)
{
    // bad username
}
else
{
    $pre_user = mysql_fetch_array($query);
    if(md5(md5($pre_user['salt']).md5($password)) == $pre_user['password'])
    {
        // good password
    }
    else
    {
        // bad password
    }
}
I'll try it.
Thank you very much! Smile