I'm trying to use php to create password hashes acceptable by django, I tried using php function hash_pbkdf2
and then base64_encode
, then making it into django's password format algorithm$iterations$salt$hash
. I also used 320000 iterations (same as django) and created a random string for salt.
$n=22;
function getName($n) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $n; $i++) {
$index = rand(0, strlen($characters) - 1);
$randomString .= $characters[$index];
}
return $randomString;
}
$pass = "erf1377";
$iterations = 320000;
$salt = getName($n);
$hash = hash_pbkdf2("sha256", $pass, $salt, $iterations);
$hash = base64_encode($hash);
$final_hash = "pbkdf2_sha256$".$iterations."$".$salt."$".$hash;
echo $final_hash;
getName()
creates my salt
But the end result is not accepted by django. what am I doing wrong here?