gpt4 book ai didi

php - 散列密码 : hash() expects at least 2 parameters, 1 给定 APP/Model/Entity/User.php 时 CakePHP 3 出错

转载 作者:行者123 更新时间:2023-11-29 03:29:48 25 4
gpt4 key购买 nike

我正在关注官方书签教程:http://book.cakephp.org/3.0/en/quickstart.html#bookmarker-tutorial

但是在将 _setPassword($value) 方法添加到我的 User 类后,我收到了这些警告,阻止我保存散列密码 在我的 users 表中正确。

Warning (2): hash() expects at least 2 parameters, 1 given [APP/Model/Entity/User.php, line 26]Warning (4096): Object of class Cake\Auth\DefaultPasswordHasher could not be converted to string [APP/Model/Entity/User.php, line 26]Notice (8): Undefined variable: _SESSION [CORE/src/Network/Session.php, line 440]
  • 这是我在App\Model\Entity\User中的方法:
    protected function _setPassword($value)    {        $hasher = new DefaultPasswordHasher();        return $hasher.hash($value);    }
  • 我在数据库中的密码字段的长度为255(有些人报告由于 MySQL 中的字段长度和新的加密方法而出现问题CakePHP 3 使用)。

  • 我的 PHP 版本是 PHP 5.5.20 (cli)(构建时间:2015 年 2 月 25 日 23:30:53)

  • 在我的error.log 中,我看到以下几行:

2015-08-08 21:43:56 Warning: Warning (2): hash() expects at least 2 parameters, 1 given in [/Applications/AMPPS/www/projects/bookmarker/src/Model/Entity/User.php, line 26]Trace:Cake\Error\BaseErrorHandler::handleError() - CORE/src/Error/BaseErrorHandler.php, line 139hash - [internal], line ??App\Model\Entity\User::_setPassword() - APP/Model/Entity/User.php, line 26Cake\ORM\Entity::set() - CORE/src/Datasource/EntityTrait.php, line 254Cake\ORM\Marshaller::merge() - CORE/src/ORM/Marshaller.php, line 467Cake\ORM\Table::patchEntity() - CORE/src/ORM/Table.php, line 2032App\Controller\UsersController::edit() - APP/Controller/UsersController.php, line 75Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 411Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 114Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 87[main] - ROOT/webroot/index.php, line 372015-08-08 21:43:56 Warning: Warning (4096): Object of class Cake\Auth\DefaultPasswordHasher could not be converted to string in [/Applications/AMPPS/www/projects/bookmarker/src/Model/Entity/User.php, line 26]Trace:Cake\Error\BaseErrorHandler::handleError() - CORE/src/Error/BaseErrorHandler.php, line 139App\Model\Entity\User::_setPassword() - APP/Model/Entity/User.php, line 26Cake\ORM\Entity::set() - CORE/src/Datasource/EntityTrait.php, line 254Cake\ORM\Marshaller::merge() - CORE/src/ORM/Marshaller.php, line 467Cake\ORM\Table::patchEntity() - CORE/src/ORM/Table.php, line 2032App\Controller\UsersController::edit() - APP/Controller/UsersController.php, line 75Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 411Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 114Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 87[main] - ROOT/webroot/index.php, line 37
  • 使用控制台时也会发生同样的情况:
    ➜  bookmarker git:(master) ✗ bin/cake console    Welcome to CakePHP v3.0.11 Console    ---------------------------------------------------------------    App : src    Path: /Applications/AMPPS/www/projects/bookmarker/src/    ---------------------------------------------------------------    You can exit with `CTRL-C` or `exit`    Psy Shell v0.5.2 (PHP 5.5.20 — cli) by Justin Hileman    >>> $u = new App\Model\Entity\User;    => App\Model\Entity\User {#212         +"[new]": true,         +"[accessible]": [           "*" => true,         ],         +"[dirty]": [],         +"[original]": [],         +"[virtual]": [],         +"[errors]": [],         +"[repository]": null,       }    >>> $u->set('password', 'a password');    PHP warning:  hash() expects at least 2 parameters, 1 given in /Applications/AMPPS/www/projects/bookmarker/src/Model/Entity/User.php on line 26    >>> $u->password    => null

最佳答案

方法_setPassword应该

 return $hasher->hash($value); 

代替

return $hasher.hash($value);

关于php - 散列密码 : hash() expects at least 2 parameters, 1 给定 APP/Model/Entity/User.php 时 CakePHP 3 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31898931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com