本文整理汇总了PHP中PasswordHash::pbkdf2方法的典型用法代码示例。如果您正苦于以下问题:PHP PasswordHash::pbkdf2方法的具体用法?PHP PasswordHash::pbkdf2怎么用?PHP PasswordHash::pbkdf2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PasswordHash
的用法示例。
在下文中一共展示了PasswordHash::pbkdf2方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate_password
public function validate_password($password, $correct_hash)
{
$params = explode(":", $correct_hash);
if (count($params) < HASH_SECTIONS) {
return false;
}
$pbkdf2 = base64_decode($params[HASH_PBKDF2_INDEX]);
return PasswordHash::slow_equals($pbkdf2, PasswordHash::pbkdf2($params[HASH_ALGORITHM_INDEX], $password, $params[HASH_SALT_INDEX], (int) $params[HASH_ITERATION_INDEX], strlen($pbkdf2), true));
}
示例2: PasswordHash
* POSSIBILITY OF SUCH DAMAGE.
*/
require_once 'PasswordHash.php';
$MyHash = new PasswordHash();
echo "Sample hash:\n";
$hash = $MyHash->create_hash("test_password");
echo $hash . "\n";
echo "Sample hash:\n";
$hash = $MyHash->create_hash("rugger31");
echo $hash . "\n";
echo "Sample hash:\n";
$hash = $MyHash->create_hash("Rugger31!");
echo $hash . "\n";
echo "\nTest results:\n";
// Test vector raw output.
$a = bin2hex($MyHash->pbkdf2("sha1", "password", "salt", 2, 20, true));
$b = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
if ($a === $b) {
echo "pass\n";
} else {
echo "FAIL\n";
}
// Test vector hex output.
$a = $MyHash->pbkdf2("sha1", "password", "salt", 2, 20, false);
$b = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
if ($a === $b) {
echo "pass\n";
} else {
echo "FAIL\n";
}
$hash_of_password = $MyHash->create_hash("password");