![](/img/trans.png)
[英]How to fix PHP 7.2 explode() expects at least 2 parameters, 1 given in
[英]Error in CakePHP 3 when hashing passwords: hash() expects at least 2 parameters, 1 given APP/Model/Entity/User.php
我正在關注官方書簽器教程 : http : //book.cakephp.org/3.0/en/quickstart.html#bookmarker-tutorial
但是在向我的User類添加_setPassword($ value)方法后,我收到了這些警告,這些警告使我無法將哈希密碼正確保存在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]
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 139 hash - [internal], line ?? App\Model\Entity\User::_setPassword() - APP/Model/Entity/User.php, line 26 Cake\ORM\Entity::set() - CORE/src/Datasource/EntityTrait.php, line 254 Cake\ORM\Marshaller::merge() - CORE/src/ORM/Marshaller.php, line 467 Cake\ORM\Table::patchEntity() - CORE/src/ORM/Table.php, line 2032 App\Controller\UsersController::edit() - APP/Controller/UsersController.php, line 75 Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 411 Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 114 Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 87 [main] - ROOT/webroot/index.php, line 37 2015-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 139 App\Model\Entity\User::_setPassword() - APP/Model/Entity/User.php, line 26 Cake\ORM\Entity::set() - CORE/src/Datasource/EntityTrait.php, line 254 Cake\ORM\Marshaller::merge() - CORE/src/ORM/Marshaller.php, line 467 Cake\ORM\Table::patchEntity() - CORE/src/ORM/Table.php, line 2032 App\Controller\UsersController::edit() - APP/Controller/UsersController.php, line 75 Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 411 Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 114 Cake\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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.