Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,295 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,192 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Auto add users from site db to phpbb db

 
Reply to this topicStart new topic

Auto add users from site db to phpbb db

King8654
post 18 Jul, 2008 - 10:46 AM
Post #1


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 89


My Contributions


Hey,

I just implemented phpbb 3 on my site, and everything working perfectly. But im not wondering if its possible to register on my site, and have that reg info carry over to the bb database. the site and the forum on diff db, one king8654_exams, and one king8654_phpBB3. Is this possible? I was trolling the support forums, and beside some snippets people individually wrote, there doesnt seem to be any official way of doing this. Am i wrong??

would it be as easy as when the user registers to add the user info to both db's in their respective folders, sort of a cloning method? Any help would be much appreciated, thanks guys!

Bryan
User is offlineProfile CardPM

Go to the top of the page


King8654
post 18 Jul, 2008 - 04:16 PM
Post #2


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 89


My Contributions


Alright, I stumbled across a script that supposedly does the job.

Heres the php file

CODE

<?php


/* A class to allow synching a PHPBB3 install with an applications user base
*
* Version: 0.1
*
* Functionality:
* --------------
* Add a user to PHPBB3
* Change users password on PHPBB3
* Disable/ban user on PHPBB3
* Enable/un-ban user on PHPBB3
*
* Please Note:
* ------------
* No validation of paramaters is undertaken, this class is expected to
* be used well behind validation regions
*
* Compliments of http://www.polr.co.uk
* - Jonathan Gibb
*/


error_reporting ( E_ALL );

class Phpbb3Integration {
    
    var $table_prefix;
    var $connection;
    
    function Phpbb3Integration($table_prefix = 'phpbb_') {
        
        $this->table_prefix = $table_prefix;
    }
    
    function connect($server,$dbuser,$dbpass,$dbname) {
        $this->connection = mysql_connect ( $server, $dbuser, $dbpass );
        if (! $this->connection) {
            return false;
        }
        
        if (! mysql_select_db ( $dbname, $this->connection )) {
            return false;
        }
        return true;
    }
    
    function addNewUser($username,$password,$email,$ip) {
        $sql = $this->createSqlToAddUserRow ( $username, $password, $email, $ip );
        mysql_query ( $sql, $this->connection );
        $id = mysql_insert_id ( $this->connection );
        $sql = $this->createSqlToAddUserGroupRow ( $id );
        mysql_query ( $sql, $this->connection );
    }
    
    function changeUserPassword($username,$password) {
        $sql = $this->createSqlToUpdateUserPassword ( $username, $password );
        mysql_query ( $sql, $this->connection );
    }
    
    function disableUser($username) {
        // first get phpbb internal id for username
        $sql = "select user_id from " . $this->table_prefix . "users where username = '$username'";
        $query = mysql_query ( $sql, $this->connection );
        if (! $query) {
            return false;
        }
        
        $id = mysql_result ( $query, 0 );
        
        // create ban row
        $banSql = "insert into " . $this->table_prefix . 'banlist (ban_userid,  ban_start,  ban_reason, ban_give_reason)';
        $banSql .= "values ('$id','" . time () . "', 'External Integration','Banned by External Integration')";
        
        mysql_query ( $banSql, $this->connection );
    
    }
    
    function enableUser($username) {
        
        // first get phpbb internal id for username
        $sql = "select user_id from " . $this->table_prefix . "users where username = '$username'";
        $query = mysql_query ( $sql, $this->connection );
        if (! $query) {
            return false;
        }
        
        $id = mysql_result ( $query, 0 );
        
        // create ban row
        $deleteSql = "DELETE FROM " . $this->table_prefix . 'banlist where ban_userid = ' . $id;
        $query = mysql_query ( $deleteSql, $this->connection );
        
        return ($query != false);
    }
    
    // Helper Methods
    
    /**
     * 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 .= $this->_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 .= $this->_hash_encode64 ( $hash, 16, $itoa64 );
        
        return $output;
    }
    
    function unique_id($extra = 'c') {
        static $dss_seeded = false;
        global $config;
        
        $val = $config ['rand_seed'] . microtime ();
        $val = md5 ( $val );
        $config ['rand_seed'] = md5 ( $config ['rand_seed'] . $val . $extra );
        
        $dss_seeded = true;
        return substr ( $val, 4, 16 );
    }
    
    function phpbb_hash($password) {
        $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
        
        $random_state = $this->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 ( $this->unique_id () . $random_state );
                $random .= pack ( 'H*', md5 ( $random_state ) );
            }
            $random = substr ( $random, 0, $count );
        }
        
        $hash = $this->_hash_crypt_private ( $password, $this->_hash_gensalt_private ( $random, $itoa64 ), $itoa64 );
        
        if (strlen ( $hash ) == 34) {
            return $hash;
        }
        
        return md5 ( $password );
    }
    
    function createSqlToAddUserRow($username,$password,$email,$ip) {
        $sql = "INSERT INTO `" . $this->table_prefix . "users` (";
        $sql .= "`user_id`, `user_type`, `group_id`, `user_permissions`, `user_perm_from`, `user_ip`, `user_regdate`, `username`, `username_clean`, `user_password`, `user_passchg`, `user_pass_convert`, `user_email`, `user_email_hash`, `user_birthday`, `user_lastvisit`, `user_lastmark`, `user_lastpost_time`, `user_lastpage`, `user_last_confirm_key`, `user_last_search`, `user_warnings`, `user_last_warning`, `user_login_attempts`, `user_inactive_reason`, `user_inactive_time`, `user_posts`, `user_lang`, `user_timezone`, `user_dst`, `user_dateformat`, `user_style`, `user_rank`, `user_colour`, `user_new_privmsg`, `user_unread_privmsg`, `user_last_privmsg`, `user_message_rules`, `user_full_folder`, `user_emailtime`, `user_topic_show_days`, `user_topic_sortby_type`, `user_topic_sortby_dir`, `user_post_show_days`, `user_post_sortby_type`, `user_post_sortby_dir`, `user_notify`, `user_notify_pm`, `user_notify_type`, `user_allow_pm`, `user_allow_viewonline`, `user_allow_viewemail`, `user_allow_massemail`, `user_options`, `user_avatar`, `user_avatar_type`, `user_avatar_width`, `user_avatar_height`, `user_sig`, `user_sig_bbcode_uid`, `user_sig_bbcode_bitfield`, `user_from`, `user_icq`, `user_aim`, `user_yim`, `user_msnm`, `user_jabber`, `user_website`, `user_occ`, `user_interests`, `user_actkey`, `user_newpasswd`, `user_form_salt`";
        $sql .= ")";
        $sql .= "VALUES (";
        $sql .= "NULL, '0', '2', '00000000006xv1ssxs\ni1cjyo000000\nqlc4pi000000\nzik0zi000000', '0', '" . $ip . "', '" . time () . "', '$username', '$username',";
        $sql .= "'" . $this->phpbb_hash ( $password ) . "', '" . time () . "', '0', '$email',";
        $sql .= " '0', '', '" . time () . "', '" . time () . "', '" . time () . "', '', '',";
        $sql .= "'0', '0', '0', '0', '0', '0', '0',";
        $sql .= "'en', '0.00', '0', 'D M d, Y g:i a', '1', '0',";
        $sql .= "'', '0', '0', '0', '0', '-3', '0', '0', 't', 'd', '0', 't', 'a', '0', '1', '0', '1', '1', '1',";
        $sql .= "'1', '895', '', '0', '0', '0', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '1a99da7f3160cc5c'";
        $sql .= ")";
        
        return $sql;
    }
    
    function createSqlToAddUserGroupRow($phpbb_user_id) {
        $sql = "INSERT INTO `" . $this->table_prefix . "user_group` (`group_id`, `user_id`, `group_leader`, `user_pending`) VALUES ('2', '$phpbb_user_id', '0', '0')";
        return $sql;
    }
    
    function createSqlToUpdateUserPassword($username,$newPassword) {
        $sql = "update `" . $this->table_prefix . "users` set user_password = '" . $this->phpbb_hash ( $newPassword ) . "' where username = '" . $username . "'";
        return $sql;
    }
    


}

?>


and it says this is the code that will call the function and allow it to work

CODE

require (FILE_ROOT . ‘forumIntegration/PHPBB3Integration.php’);
$forum = new Phpbb3Integration ( );
$forum->connect ( BBDBSERVER, BBDBUSER, BBDBPASS, BBDBNAME );
$forum->addNewUser ( $user->getUsername (), $user->getPassword (), $user->getEmailAddress (), $user->getRegistrationIp () );


Now im wondering....does this snippet go on the join page when the user registers and captures the info at the click of the submit button? Any guidance would be appreciated.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/6/08 09:26AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month