Microalg / microalg

Langage et environnements dédiés à l’algorithmique.
http://microalg.info
GNU General Public License v2.0
12 stars 3 forks source link

Galerie (Dokuwiki): Bridger l’authentication avec Askbot #55

Open Grahack opened 10 years ago

Grahack commented 10 years ago

Plugins existants:

Bout de code qui fonctionne pour authentifier contre un hash Django depuis PHP:


$dbconn = pg_connect("host=postgresql1.alwaysdata.com dbname=tavu user=oubien password=oubienbienoubien");
$result = pg_query($dbconn, "select username, password from auth_user where username='$user';");
if ($result) {
        $result_array = pg_fetch_array($result, 0);
        $pbkdf_hash = $result_array['password'];
} else {
        echo "pas de resultat";
}
pg_close($dbconn);

$pieces = explode('$', $pbkdf_hash);
$iterations = $pieces[1];
$salt = $pieces[2];
$stored_hash = $pieces[3];

$recalculated = base64_encode(hash_pbkdf2("sha256", $pass, $salt, $iterations, 32, true));

if ($recalculated == $stored_hash)
{
    echo ("SUCCESS");
}
else
{
    echo ("FAILED");
}