1 (edited by versgui 2007-08-07 11:35)

Topic: [solved] Modification of the login system

Hello!

First of all, please excuse me for my rather average English :-)

I currently make with my PunBB installation : I wish in fact that when somebody is registered on my site, it be registered at the same time on the forum. I thus modified the file login.php so that PHP can call it with an include(): I passed all the variables $_POST to $_GET.

Here what login.php resembles:

<?php
define('PUN_QUIET_VISIT', 1);

define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

$form_username = trim($_GET['req_username']);
$form_password = trim($_GET['req_password']);

$username_sql = ($db_type == 'mysql' || $db_type == 'mysqli') ? 'username=\''.$db->escape($form_username).'\'' : 'LOWER(username)=LOWER(\''.$db->escape($form_username).'\')';

$result = $db->query('SELECT id, group_id, password FROM '.$db->prefix.'users WHERE '.$username_sql) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
list($user_id, $group_id, $db_password_hash) = $db->fetch_row($result);

$authorized = false;

if (!empty($db_password_hash))
{
    $sha1_in_db = (strlen($db_password_hash) == 40) ? true : false;
    $sha1_available = (function_exists('sha1') || function_exists('mhash')) ? true : false;

    $form_password_hash = pun_hash($form_password);    // This could result in either an SHA-1 or an MD5 hash (depends on $sha1_available)

    if ($sha1_in_db && $sha1_available && $db_password_hash == $form_password_hash)
        $authorized = true;
    else if (!$sha1_in_db && $db_password_hash == md5($form_password))
    {
        $authorized = true;

        if ($sha1_available)    // There's an MD5 hash in the database, but SHA1 hashing is available, so we update the DB
            $db->query('UPDATE '.$db->prefix.'users SET password=\''.$form_password_hash.'\' WHERE id='.$user_id) or error('Unable to update user password', __FILE__, __LINE__, $db->error());
    }
}

if (!$authorized)
    message("error");

// Update the status if this is the first time the user logged in
if ($group_id == PUN_UNVERIFIED)
    $db->query('UPDATE '.$db->prefix.'users SET group_id='.$pun_config['o_default_user_group'].' WHERE id='.$user_id) or error('Unable to update user status', __FILE__, __LINE__, $db->error());

// Remove this users guest entry from the online list
$db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape(get_remote_address()).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $db->error());

$expire = time() + 14400;
pun_setcookie($user_id, $form_password_hash, $expire);

// tests
print_r($_COOKIE);
exit();
}

And the result :

http://www.casimages.com/img/png/0708041149573970958103.png

The problem? As you can see it, the login functions perfectly and a cookie is correctly generated. Except that when I look in the Firefox cookies manager, I do not find this famous cookie.

I have sought for 4 days and I do not find. Would somebody have the answer?
Thank you in advance !


(in french - en français au cas où ^^)

Bonjour !
Tout d'abord, veuillez m'excuser pour mon anglais plutôt moyen :-)
Je fais actuellement avec mon installation PunBB : je souhaite en fait que quand quelqu'un s'inscrit sur mon site, il soit inscrit du même coup sur le forum.
J'ai donc modifié le fichier login.php pour que PHP puisse l'appeler depuis un include() : j'ai passé toutes les variables $_POST en $_GET.
Voici à quoi ressemble login.php :
[...]
Le problème ? Comme vous pouvez le voir, l'authentification fonctionne parfaitement et un cookie est correctement généré.
Sauf que quand je regarde dans le gestionnaire de cookies de Firefox, je ne trouve pas ce fameux cookie.
Je cherche depuis 4 jours et je ne trouve pas. Quelqu'un aurait-il la réponse ?
Merci d'avance !

Re: [solved] Modification of the login system

I'm not sure if what you put in that searchbox is the name of the site or the name of the cookie. wink

3 (edited by versgui 2007-08-05 11:07)

Re: [solved] Modification of the login system

There is no problem with that, I tested with other sites smile
And PunBB always takes to me for a guest after login.

Re: [solved] Modification of the login system

Well $_COOKIE isn't modified when you call pun_setcookie, so I'm not sure exactly what you're seeing there wink
Could you provide a link?

Re: [solved] Modification of the login system

Ok, here : http://www.bouzouks.net/testpunbb/login.html (keep default values)

For information, my config file :

$cookie_name = 'tobopunbb';
$cookie_domain = 'bouzouks.net';
$cookie_path = '/';
$cookie_secure = 0;

Re: [solved] Modification of the login system

$cookie_domain = '.bouzouks.net';

Try that wink

Re: [solved] Modification of the login system

No change :\

Re: [solved] Modification of the login system

Well, looking at the headers your script sends, it doesn't even try to send a cookie.
And the post variables login.html sends don't match your script above.

Re: [solved] Modification of the login system

There isn't problem with variables name, else the identification would not function (the form is send to a file who changes variables names and include the punbb's login file).

I've all tested with LiveHTTPHeader (http://www.bouzouks.net/testpunbb/resultheaders.txt) but I didn't find anything who could to help me.

Too, I've disabled the session system of my website, but there is no change sad

Re: [solved] Modification of the login system

I tested with LiveHTTPHeaders too: as you pointed out, there's no cookie being set there.
Without FTP access or something to check out the actual code being run, there isn't much more I can do.

Re: [solved] Modification of the login system

No problem, I've sent this on your email address. smile

Re: [solved] Modification of the login system

I haven't gotten any email hmm

Re: [solved] Modification of the login system

Er...
Can you send your address at [email]or here, please ?

Re: [solved] Modification of the login system

Done