1

Topic: WordPress 2.8.4 и punBB 1.3 Integration Problem

Decided to integrate WordPress 2.8.4 and punBB 1.3 Integration. Like a WordPress user registration is progressing smoothly and the Wordpress database and forum, but why is the forum in the database table pun_users in the graph of the newly created user's password is the value BRAK. I understand it from the fact that Wordpress and punBB use different encryption password.

Help me Friends.

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

Here the peace of code, which used for password hash generation:

$salt = random_key(12);
$password_hash = forum_hash($password1, $salt);

The "random_key" function generates a random string which is called "salt" (it is stored in the table "users"). Then generates a password hash with "forum_hash" function. Both these functions you can find in the file "<FORUM_ROOT>/include/functions.php".

3

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

Please help me to apply these functions in the plugin punBB integrator version: 0.0.07.2008.01

4

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

problem is relevant

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

Please, describe in details what you expect from us.

6

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

What do I need to write up a plugin wordpress, for the normal passage of a password to the database offline, and not BRAK, as now.

plugin code:

<?php
/*
Plugin Name: punBB integrator
Plugin URI: http://www.rkblog.rk.edu.pl
Description: Allows Wordpress to manager punBB users - login/logout/register/password change etc.
Version: 0.0.07.2008.01
Author: Riklaunim
Author URI: http://www.rkblog.rk.edu.pl
*/
//add_action('profile_update', 'punbb_profile_update');
//add_action('wp_logout', 'punbb_wp_logout');
//add_action('wp_authenticate', 'punbb_wp_authenticate', 1, 2);
add_action('user_register', 'punbb_user_register');
add_action('activate_jl-punbb/jl-punbb.php', 'punbb_sync_tables');

define('PUNPATH', '/forum'); // path to punbb folder
define('PUNPREFIX', 'pun_'); // punBB table prefix
define('LANGUAGE', 'English'); // punBB language name, English, etc.

function forum_hash($str, $salt)
{
    return sha1($salt.sha1($str));
}

function punbb_sync_tables()
    {
    global $wpdb;
    // copy users from WP to punBB that doesn't have account on punBB
    $q = $wpdb->get_results("SELECT * FROM ".$wpdb->users." WHERE user_login NOT IN (SELECT username FROM ".PUNPREFIX."users)");
    foreach($q as $u)
        {
        // give forum admin to the WP admin.
        IF($u->ID == 1)
            {
            $gid = 1;
            }
        else
            {
            $gid = 3;
            }
        $salt = md5(sha1(time().$u->user_login));
        $salt = substr($salt, 0,11);
        $wpdb->query('INSERT INTO '.PUNPREFIX.'users (username, group_id, password, email, email_setting, timezone, language, style, registered, registration_ip, last_visit, salt) VALUES(\''.$u->user_login.'\', '.$gid.', \'BRAK\', \''.$u->user_email.'\', 1, 1 , \''.LANGUAGE.'\', \'Oxygen\', '.time().', \''.strip_tags($_SERVER['REMOTE_ADDR']).'\', '.time().', \''.$salt.'\')');
        }
    // turn off emails for "dectivated" accounts on forum
    $wpdb->query('UPDATE '.PUNPREFIX.'users SET email_setting = 2 WHERE username NOT IN (SELECT user_login FROM '.$wpdb->users.') AND id > 1');
    }
    
function punbb_profile_update($id)
    {
    global $wpdb;
    $wpuser = $wpdb->get_row("SELECT user_login, user_email FROM ".$wpdb->users." WHERE ID = ".$id." LIMIT 1");
    $wpdb->query("UPDATE ".PUNPREFIX."users SET email='".$wpuser->user_email."' WHERE username = '".$wpuser->user_login."'");
    }
function punbb_wp_logout()
    {
    include PUNPATH.'/config.php';
    setcookie($cookie_name, NULL, time()-3600, '/', 'sgt.su', '0');
    }
function punbb_wp_authenticate($user_login, $user_pass)
    {
    global $wpdb;
    // wywoЕ‚aj przy logowaniu jak masz dane
    IF($user_login and $user_pass and strlen($user_login) > 1 and strlen($user_pass) > 1)
        {
        $wpuser = $wpdb->get_row("SELECT id,user_pass FROM ".$wpdb->users." WHERE user_login = '".mysql_real_escape_string($user_login)."' LIMIT 1");
        if(wp_check_password($user_pass, $wpuser->user_pass, $wpuser->id))
            {
            $user = $wpdb->get_row("SELECT id, password, salt FROM ".PUNPREFIX."users WHERE username = '".mysql_real_escape_string($user_login)."' LIMIT 1");
            include PUNPATH.'/config.php';
            /*
            punBB uses sha1, wordpress md5. We have to cheat a bit. If the sha1 hash-password in punBB is "BRAK" (look at punbb_user_register)
            or it doesn't match sha1(password from good authentication) then we update it :)
            */
            IF($user->password == 'BRAK' OR sha1($user_pass) != $user->password)
                {
                $wpdb->query("UPDATE ".PUNPREFIX."users SET password='".sha1($user_pass)."' WHERE username = '".mysql_real_escape_string($user_login)."'");
                $user->password = sha1($user_pass);
                }
            $expire = time() + 31536000;
            
            //here we can get many informations
            $userInfoArray = $wpdb->get_row("SELECT id, group_id, password, salt FROM ".PUNPREFIX."users WHERE username='".mysql_real_escape_string($user_login)."'", "ARRAY_A");
            $salt = $userInfoArray['salt'];
            $form_password_hash = forum_hash($user_pass, $salt);
            $base64 = base64_encode($user->id.'|'.$user->password.'|'.$expire.'|'.sha1($user->salt.$user->password.forum_hash($expire, $user->salt)));
            if (version_compare(PHP_VERSION, '5.2.0', '>='))
                {
                setcookie($cookie_name, $base64, $expire, $cookie_path, $cookie_domain, $cookie_secure, true);
                }
            else
                {
                setcookie($cookie_name, $base64, $expire, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure);
                }
            }
         }
    }
function punbb_user_register($id)
    {
    global $wpdb;
    $wpuser = $wpdb->get_row("SELECT * FROM ".$wpdb->users." WHERE ID = ".$id." LIMIT 1");
    $user = $wpdb->get_row("SELECT id FROM ".PUNPREFIX."users WHERE username = '".mysql_real_escape_string($wpuser->user_login)."' LIMIT 1");
    // user already exists in punbb
    IF($user->id)
        {
        $wpdb->query("UPDATE ".PUNPREFIX."users SET password='BRAK' WHERE username = '".mysql_real_escape_string($wpuser->user_login)."'");
        }
    // user does not exists
    else
        {
        $salt = md5(sha1(time()));
        $salt = substr($salt, 0,11);
        $wpdb->query('INSERT INTO '.PUNPREFIX.'users (username, group_id, password, email, email_setting, timezone, language, style, registered, registration_ip, last_visit, salt) VALUES(\''.$wpuser->user_login.'\', 3, \'BRAK\', \''.$wpuser->user_email.'\', 1, 1 , \''.LANGUAGE.'\', \'Oxygen\', '.time().', \''.strip_tags($_SERVER['REMOTE_ADDR']).'\', '.time().',\''.$salt.'\')');
        }
    }

?>

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

you shouldn't integrate these 2...

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

So, the password is being updated in function punbb_wp_authenticate. But you have commented registering of this function for some reason.

I suppose the password isn't set while user registers because one can't restore the password from md5-hash stored in WP tables. Script knows the user password only when the user is logging in.

9

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

Parpalak wrote:

So, the password is being updated in function punbb_wp_authenticate. But you have commented registering of this function for some reason.

I suppose the password isn't set while user registers because one can't restore the password from md5-hash stored in WP tables. Script knows the user password only when the user is logging in.

   
I am in php is not very good judge. If not hard to help tweak this plugin.

Re: WordPress 2.8.4 и punBB 1.3 Integration Problem

It's a plugin for WordPress, not for PunBB. I didn't look into the WordPress code much and I can't help you. Why not to ask the author of this plugin?