I met the same situation as you did, Prateek, and with some studies, the following codes did what I want, and it's what you want.
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
function make_password($password) {
$algorithm = "pbkdf2_sha256";
$iterations = 10000;
$newSalt = mcrypt_create_iv(6, MCRYPT_DEV_URANDOM);
$newSalt = base64_encode($newSalt);
$hash = hash_pbkdf2("SHA256", $password, $newSalt, $iterations, 0, true);
$toDBStr = $algorithm ."$". $iterations ."$". $newSalt ."$". base64_encode($hash);
// This string is to be saved into DB, just like what Django generate.
echo $toDBStr;
}
function verify_Password($dbString, $password) {
$pieces = explode("$", $dbString);
$iterations = $pieces[1];
$salt = $pieces[2];
$old_hash = $pieces[3];
$hash = hash_pbkdf2("SHA256", $password, $salt, $iterations, 0, true);
$hash = base64_encode($hash);
if ($hash == $old_hash) {
// login ok.
return true;
}
else {
//login fail
return false;
}
}
?>
The $toDBStr generated in make_password is exactly the same as what you post in this thread, and you can save the string to any database, even keep use the DB created by Django.
And you need to select the string to pass to the verify_Password function to verify if the password is the same as what user inputed.
The above PHP code requires PHP 5.5 to have the hash_pbkdf2 function.
Enjoy it.