我可以为php提供以下解决方案:/*
* This function creates a passlib-compatible pbkdf2 hash result. Parameters are:
* $algo - one of the algorithms supported by the php `hash_pbkdf2()` function
* $password - the password to hash, `hash_pbkdf2()` format
* $salt - a random string in ascii format
* $iterations - the number of iterations to use
*/
function create_passlib_pbkdf2($algo, $password, $salt, $iterations)
{
$hash = hash_pbkdf2($algo, $password, base64_decode(str_replace(".", "+", $salt)), $iterations, 64, true);
return sprintf("\$pbkdf2-%s\$%d\$%s\$%s", $algo, $iterations, $salt, str_replace("+", ".", rtrim(base64_encode($hash), '=')));
}
我将salt、迭代和算法从现有的passlib生成的哈希字符串中复制出来,并向它们提供这个函数的明文密码,它将生成与passlib相同的结果。在
下面是一个php函数,用于验证passlib pbkdf2密码,基于上述内容:
^{pr2}$