1 (edited by thetoolsmith 2012-02-22 17:14)

Topic: Why is my external login not working?

I have a growing site that has 100+ new sign ups a day and would really like to offer PunBB version 1.4 as my forum solution. I currently handle registrations and login via my site so I'd like to offer my users the ability to start posting once they've registered and logged in from the main site.

Are there examples of other sites that have done something similar or any docs that might point me in the right direction?  I'm assuming I'll need to pre-populate the users table with the required info.  After that do I create a session or cookie value to allow users to start posting?

ok, after playing with the code this is what I have so far. This block sits inside a private function I currently use to login.

                if(!defined('FORUM_ROOT')) {
                    define('FORUM_ROOT', 'forum/');
                }
                
                global $forum_db;
               
                require_once FORUM_ROOT.'config.php';
                require_once FORUM_ROOT.'include/functions.php';
                require_once FORUM_ROOT.'include/dblayer/common_db.php';
                
                // username from my login and also exists in the forum DB
                $username = $this->user; 
                
                $dbhost = 'localhost';
                $dbuser = 'root';
                $dbpasswd = 'password';
                $dbname = 'forum';
                
                $conn = mysql_connect($dbhost, $dbuser, $dbpasswd) or die ('Error connecting to mysql');
                mysql_select_db("$dbname",$conn) or die ("could not open db".mysql_error());
                
                $queryFromPunbb = "SELECT * FROM users WHERE username='$username'";   
                $result = mysql_query($queryFromPunbb, $conn) or die (mysql_error());   
                $forum_user= mysql_fetch_array($result) or die(mysql_error());   

                // I've verified that these are both returning valid values
                $userId    = $forum_user['id'];
                $salt        =  $forum_user['salt'];

                $password  = $this->pass;
                $hash      = forum_hash($password, $salt);
                $saveLogin = 0;
                
                $expire = time()+60*60*24*30;
                
                forum_setcookie($cookie_name, base64_encode($userId.'|'.$hash.'|'.$expire.'|'.sha1($salt.$hash.forum_hash($expire, $salt))), $expire);
                
                cookie_login($forum_user);

Any idea what I'm missing or how to troubleshoot this further?

Thanks,
-Paul

2 (edited by thetoolsmith 2012-02-22 17:34)

Re: Why is my external login not working?

After further investigation I see that the cookie is getting set like so after login:

Set-Cookie:forum_cookie_274b0d=M3wzMTVkNGZhNJUxOWUyMWZiYmZiNWEyZjVmNjE1NmE5M2IyMTQ5OGQ2fDEzMjk5MzY4NTl8ZTYzZTM3OGY2OTcwODAyNDgxMDk0MjUwMmExYzhiMDA2YjU5YjQ1Zg%3D%3D; expires=Wed, 22-Feb-2012 18:54:19 GMT; path=/; 

If I look at the cookie returned after navigating to the index.php page of the forum I see a cookie returned that looks like this:

Set-Cookie:forum_cookie_274b0d=MXxiOWVjY2E1YnwxMzMxMTQxMzQ5fDJkZGM5MjNh; expires=Wed, 07-Mar-2012 17:29:09 GMT; path=/;

Any idea why it's different or what I need to do to keep the one I initially set?

Re: Why is my external login not working?

cookie_name is configured variable

    function set_cookie($name, $value, $expire) {
        header('P3P: CP="CUR ADM"');
        if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
            setcookie($this->conf['cookie_name'], $value, $expire, $this->conf['cookie_path'], $this->conf['cookie_domain'], $this->conf['cookie_secure'], true);
        } else {
            setcookie( $this->conf['cookie_name'], $value, $expire, $this->conf['cookie_path'].'; HttpOnly', $this->conf['cookie_domain'], $this->conf['cookie_secure']);
        }
    }

We need value and expire