Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 集成密码兼容库_Php_Codeigniter_Bcrypt - Fatal编程技术网

Php 集成密码兼容库

Php 集成密码兼容库,php,codeigniter,bcrypt,Php,Codeigniter,Bcrypt,这不是我第一次使用CodeIgniter或Bcrypt,但这是我第一次使用一个我在将两者集成在一起时遇到的问题 让我们来看看代码: public function create_user($value) { $this -> CI = get_instance(); // Get the CI instance $this -> CI -> load -> library('bcrypt'); // Use this to load th

这不是我第一次使用CodeIgniter或Bcrypt,但这是我第一次使用一个我在将两者集成在一起时遇到的问题

让我们来看看代码:

 public function create_user($value) {
        $this -> CI = get_instance(); // Get the CI instance
        $this -> CI -> load -> library('bcrypt'); // Use this to load the library from within the model 

        $hash = $this -> CI -> bcrypt -> password_hash($value[":password"], PASSWORD_BCRYPT, array("cost" => 17)); Here is where things get shaky.

        $value[":password"] = $hash; // Here I take the :password placeholder and update the clear text password with the bcrypt pasword

        var_dump($value[":password"]); // This gives me NULL, I assume because I am getting errors with $hash = .......

 ........................................
根据带有密码的手册:

BCRYPT还允许您在选项中定义成本参数 数组。这允许您更改算法的CPU成本:

$hash=password\u hash($password,password\u BCRYPT,数组(“cost”=> 10));

在我的前端,我经常会遇到以下错误:

消息:使用未定义的常量密码\u BCRYPT-假定 “密码\u BCRYPT”

消息:password_hash()要求参数2为长字符串

我把它放进了一个库,所以我把它放进了application/library文件夹

任何帮助都会很好。谢谢。

好的(这是我以前的Bcrypt.php文件)

您注意到我没有添加这些行:

if (!defined('PASSWORD_DEFAULT')) {

    define('PASSWORD_BCRYPT', 1);
    define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
我删除它们的原因是因为我把上面的代码片段放在类Bcrpyt{…行下面,这会导致错误

现在我把这段代码放在下面:

if (!defined('PASSWORD_DEFAULT')) {
        define('PASSWORD_BCRYPT', 1);
        define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);

  Class Bcrypt {
这就是我为它工作所做的一切。愚蠢的我!现在它工作了:

字符串(60) “$2y$17$9qgFDbN3361DAQFilGZySuJ4czachQThuskoSj4DihkxjwGFqTx2e”


你正在运行PHP5.5+?看起来那个常数在那之前没有添加,这也会导致关于param 2的消息不是预期的。我正在运行PHP5.3和sushin patchYa,密码_BCRYPT常数直到5.5才被引入。我是个十足的白痴。哇。我会回答这个问题。很抱歉浪费你的时间!