Topic: punbb setcookie() and trying to integrate login
Hello,
I'm trying to login to punbb from my own code. I understand that I need to call setcookie().
I can get the user's password, salt etc from the punbb database allright and I can compute the hash with sha1($salt.sha1($str)); Other values for set_cookie() can be found in config.php.
But what exactly should I put into 2e param $value please?
Edit: never mind, I think I found the solution, this seems to work. This is my code in case anybody is interested. It doesn't use any punbb functions so it is fully independant. Hope it is readable.
// input $name and $pass
$name = $_POST['name'];
$pass = $_POST['pass'];
// here of course you should connect to the punbb database first
mysql_connect(etc);
mysql_select_db('yourpunbb_database');
$query = "SELECT * FROM users WHERE username='$name'";
list($id, $hashpass, $salt) = mysql_fetch_row(mysql_query($query));
if (punhash($pass, $salt) == $hashpass) // password match?
{
puncookie($id, $hashpass, $salt); // login
header("Location: index.php");
}
//-------------------------------------------
function punhash($str, $salt)
{
return sha1($salt.sha1($str));
}
//-------------------------------------------
function puncookie($id, $pass, $salt)
{
header('P3P: CP="CUR ADM"');
$cookie_name = 'forum_cookie'; // you should get these from your config.php
$cookie_domain = '';
$cookie_path = '/';
$cookie_secure = 0;
$expire = time()+24*60*60;
$value = base64_encode($id.'|'.$pass.'|'.$expire.'|'.sha1($salt.$pass.punhash($expire, $salt)));
setcookie($cookie_name, $value, $expire, $cookie_path, $cookie_domain, $cookie_secure, true);
}
Thanks.