PHP - hash_pbkdf2函数 [英] PHP - hash_pbkdf2 function

查看:149
本文介绍了PHP - hash_pbkdf2函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个函数来使用这个php函数来哈希密码: http://be.php.net/manual/en/function.hash-pbkdf2.php



以下是代码:

  $ hash_algo =sha256; 
$ password =password;
$ salt =salt;
$ iterations = 1;
$ length = 1;
$ raw_output = false;

$ hash = hash_pbkdf2($ hash_algo,$ password,$ salt,$ iterations,$ length,$ raw_output);

echo $ hash;

我得到这个错误:致命错误:调用未定义的函数hash_pbkdf2()

函数如何被定义为不可用?



PS:我所有的变量值都是设置仅用于测试功能。显然盐不会是盐等。 编辑:<



这个函数在核心PHP中还没有(还有)。这是不久前提出的,到目前为止,您只能将其作为补丁



您可以使用 crypt hash 来代替。
crypt 实际上是在 hash_pbkdf2 文档


警告

PBKDF2方法可用于散列存储密码(NIST已批准使用该密码)。但是,应该注意 CRYPT_BLOWFISH 更适合于密码存储,应该通过 crypt()来使用。



I'm trying to do a function to hash passwords with this php function: http://be.php.net/manual/en/function.hash-pbkdf2.php.

Here is the code:

$hash_algo = "sha256";
$password = "password";
$salt = "salt";
$iterations = 1;
$length = 1;
$raw_output = false;

$hash = hash_pbkdf2($hash_algo, $password, $salt, $iterations ,$length ,$raw_output);

echo $hash;

I got this error: Fatal error: Call to undefined function hash_pbkdf2().

How can the function be undefined???

PS: All the values of my variables are set just for testing the function. Obviously the salt will not be "salt", etc.

解决方案

EDIT: As of PHP 5.5.0 this function is now bundled into the core library.


This function is not (yet anyway) available in core PHP. It was proposed not that long ago and so far you can only get it as a patch.

You can use crypt or hash instead. crypt is actually suggested in hash_pbkdf2 documentation:

Caution
The PBKDF2 method can be used for hashing passwords for storage (it is NIST approved for that use). However, it should be noted that CRYPT_BLOWFISH is better suited for password storage and should be used instead via crypt().

这篇关于PHP - hash_pbkdf2函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆