Topic: Login with a phpBB3 users table

Hello

I saw many posts about login with users from a phpBB3 forum.
I made it for my forum and it's quite easy. It's require to add phpBB3 functions
and to modify the function doauthphpBB.
After this it will works as well with a phpBB2 or phpBB3 forum

IN includes/function.php ADD

function phpbb_hash($password)
{
    $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

    $random_state = unique_id();
    $random = '';
    $count = 6;

    if (($fh = @fopen('/dev/urandom', 'rb')))
    {
        $random = fread($fh, $count);
        fclose($fh);
    }

    if (strlen($random) < $count)
    {
        $random = '';

        for ($i = 0; $i < $count; $i += 16)
        {
            $random_state = md5(unique_id() . $random_state);
            $random .= pack('H*', md5($random_state));
        }
        $random = substr($random, 0, $count);
    }
    
    $hash = _hash_crypt_private($password, _hash_gensalt_private($random, $itoa64), $itoa64);

    if (strlen($hash) == 34)
    {
        return $hash;
    }

    return md5($password);
}

/**
* Check for correct password
*/
function phpbb_check_hash($password, $hash)
{
    $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    if (strlen($hash) == 34)
    {
        return (_hash_crypt_private($password, $hash, $itoa64) === $hash) ? true : false;
    }

    return (md5($password) === $hash) ? true : false;
}

/**
* Generate salt for hash generation
*/
function _hash_gensalt_private($input, &$itoa64, $iteration_count_log2 = 6)
{
    if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
    {
        $iteration_count_log2 = 8;
    }

    $output = '$H$';
    $output .= $itoa64[min($iteration_count_log2 + ((PHP_VERSION >= 5) ? 5 : 3), 30)];
    $output .= _hash_encode64($input, 6, $itoa64);

    return $output;
}

/**
* Encode hash
*/
function _hash_encode64($input, $count, &$itoa64)
{
    $output = '';
    $i = 0;

    do
    {
        $value = ord($input[$i++]);
        $output .= $itoa64[$value & 0x3f];

        if ($i < $count)
        {
            $value |= ord($input[$i]) << 8;
        }

        $output .= $itoa64[($value >> 6) & 0x3f];

        if ($i++ >= $count)
        {
            break;
        }

        if ($i < $count)
        {
            $value |= ord($input[$i]) << 16;
        }

        $output .= $itoa64[($value >> 12) & 0x3f];
        
        if ($i++ >= $count)
        {
            break;
        }

        $output .= $itoa64[($value >> 18) & 0x3f];
    }
    while ($i < $count);

    return $output;
}

/**
* The crypt function/replacement
*/
function _hash_crypt_private($password, $setting, &$itoa64)
{
    $output = '*';

    // Check for correct hash
    if (substr($setting, 0, 3) != '$H$')
    {
        return $output;
    }

    $count_log2 = strpos($itoa64, $setting[3]);

    if ($count_log2 < 7 || $count_log2 > 30)
    {
        return $output;
    }

    $count = 1 << $count_log2;
    $salt = substr($setting, 4, 8);

    if (strlen($salt) != 8)
    {
        return $output;
    }

    /**
    * We're kind of forced to use MD5 here since it's the only
    * cryptographic primitive available in all versions of PHP
    * currently in use.  To implement our own low-level crypto
    * in PHP would result in much worse performance and
    * consequently in lower iteration counts and hashes that are
    * quicker to crack (by non-PHP code).
    */
    if (PHP_VERSION >= 5)
    {
        $hash = md5($salt . $password, true);
        do
        {
            $hash = md5($hash . $password, true);
        }
        while (--$count);
    }
    else
    {
        $hash = pack('H*', md5($salt . $password));
        do
        {
            $hash = pack('H*', md5($hash . $password));
        }
        while (--$count);
    }

    $output = substr($setting, 0, 12);
    $output .= _hash_encode64($hash, 16, $itoa64);

    return $output;
}

( This code is from includes/functions.php in a phpBB3 forum )

IN FUNCTION

doAuthphpBB($aUsername,$aPassword)

FIND

    $sql = "select * from $set_phpbb_table where user_email= '$aUsername' AND user_password=md5('" . $aPassword . "')";
    $res = mysql_query($sql,$conn_id);
    $num = mysql_num_rows($res);
    $row=mysql_fetch_array($res);
    
    if ($num>0)

REPLACE BY

    $sql = "select * from $set_phpbb_table where user_email= '$aUsername' ";
    $res = mysql_query($sql,$conn_id);
    $num = mysql_num_rows($res);
    $row=mysql_fetch_array($res);
    
    if (($num>0) AND (($row["user_password"] == md5($aPassword)) OR (phpbb_check_hash($aPassword,$row["user_password"]))))

it's test if the password is ok for a phpBB2 users table or a phpBB3 users table

if (num>0) AND ((test password for phpBB2) OR (test password for phpBB3))


I hope it will be helpfull cool

+ -

Re: Login with a phpBB3 users table

Does it really work? As far as I remember integrated in phpClass module for phpBB didn't work. By the way It's much better to use Invision Power Board or vBulletin. phpBB is one big hole for spammers and hackers.

Re: Login with a phpBB3 users table

It's working of course ... this is a strange question ...
I haven't integrate all phpBB functions, only what is necessary, and it's work.

About using phpBB or other systems, every one can choose, but when you use one system since a long time it's not easy to change.
More over phpBB is free,  for a non commercial use, it's quite important and there is a french version (i'm french ... ) smile

+ -

Re: Login with a phpBB3 users table

could not find

doAuthphpBB($aUsername,$aPassword)


which file should I locate? I search for it in function.php

+ -

Re: Login with a phpBB3 users table

It works perfect!!!!!!!!!!!!!   thanks!!!!!

Now would there be a way to use the PHPBB3 contact system? .. I mean that in phpclassifieds, when someone wants to contact a seller, its done via the phpBB private message system. Its to just have one contact center and not 2, and phpBB PM manager is great for users communication.

Also when a user changes his password in PHPBB or PhpClassifieds, both accounts passwords are not bound, and need to be updated in both places separately.

Last edited by cincen (2008-07-11 10:04:37)

+ -

Re: Login with a phpBB3 users table

do I need to config phpbb too?

+ -

Re: Login with a phpBB3 users table

I understand this as follows:
in includes / functions.php replace this line:

$sql = "select * from $set_phpbb_table where user_email= '$aUsername' AND user_password=md5('" . $aPassword . "')";
    $res = mysql_query($sql,$conn_id);
    $num = mysql_num_rows($res);
    $row=mysql_fetch_array($res);
    
    if ($num>0)

with this:

   

 $sql = "select * from $set_phpbb_table where user_email= '$aUsername' ";
    $res = mysql_query($sql,$conn_id);
    $num = mysql_num_rows($res);
    $row=mysql_fetch_array($res);
    
    if (($num>0) AND (($row["user_password"] == md5($aPassword)) OR (phpbb_check_hash($aPassword,$row["user_password"])))) 

But it does not work!

Error from Classifieds:

Error occurred
We are sorry, but an unexpected error occurred and the system could not continue serving you. Please contact the webmaster at this site ... and report the problem, along with the error message printed below. Please include any other information which may be useful to the webmaster.

For webmaster: This error with far more details has been logged in PHP Classifieds's error log

Last edited by escape (2008-11-24 16:58:56)

inseratissimo.ch - Inserate, Kleinanzeigen kostenlos und mit Fotos anbieten, suchen oder tauschen.

Re: Login with a phpBB3 users table

I kinda got this to work using the above method for phpbb3 however, it doesnt log you into both the classfieds as well as the forum. I also noticed that if you update your profile on the phpbb side (i.e: change your password) then it doesnt update the table in the classifieds database, it just creates a new user with the new info.

I want to get these things fixed so I can use the forums PM system for the "contact seller" links. if the userID's from the forum match the userids from the classifieds..this would be a simple sollution.

so basicly we need 3 things:

1. Users logining into classifieds aer also logged into phpbb

2. User_ID's from classifieds should follow user_ID's from phpbb

3. Users updated on phpbb should update upon next login to classifieds.

+ -