0

这不是我第一次使用 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 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 = .......

 ........................................

根据 Password_compat 手册:

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

$hash = password_hash($password, PASSWORD_BCRYPT, array("cost" => 10));

在我的前端,这些是我不断收到的错误:

消息:使用未定义的常量 PASSWORD_BCRYPT - 假定为“PASSWORD_BCRYPT”

消息:password_hash() 期望参数 2 很长,给定字符串

我把它做成了一个库本身,所以我把它放到了 application/librarys 文件夹中

这是文件

任何帮助都会很棒。谢谢你。

4

1 回答 1

0

好的,看看这个文件(这是我的旧 Bcrypt.php 文件)

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

if (!defined('PASSWORD_DEFAULT')) {

    define('PASSWORD_BCRYPT', 1);
    define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);

好吧,我删除它们的原因是因为我将上面的代码片段放在了 Class Bcrpyt { ... 行下,这会导致错误。

现在我把这个片段代码:

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

  Class Bcrypt {

这就是我所要做的一切。傻我!现在它起作用了:

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

于 2013-08-13T23:33:01.660 回答