<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
/**
* User Entity.
*/
class User extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
* Note that '*' is set to true, which allows all unspecified fields to be
* mass assigned. For security purposes, it is advised to set '*' to false
* (or remove), and explicitly make individual fields accessible as needed.
*
* @var array
*/
protected $_accessible = [
'*' => true,
'id' => false,
];
protected function _setPassword($value)
{
$hasher = new DefaultPasswordHasher();
return $hasher->hash($value);
}
}
这是我的代码在user.php.我是散列密码和得到这一个错误
错误:未找到类“App\Model\Entity\DefaultPasswordHasher”文件C:\xamp\htdocs\bookmarker\src\Model\Entity\User。菲律宾行:27
我错过了以下一行:
use Cake\Auth\DefaultPasswordHasher;
这就是我出错的原因。
如果您使用的是cakephp版本4.0
,并且已经在php文件中包含了这两个密码哈希:
use Authentication\PasswordHasher\DefaultPasswordHasher;
{
$hasher = new DefaultPasswordHasher();
return $hasher->hash($password);
}
正如官方cakephp 4.0文档中提到的
但仍然会出现如下错误:
Undefined type 'Authentication\PasswordHasher\DefaultPasswordHasher'.
intelephense(1009) [50,23]
.
然后,不要使用:
use Authentication\PasswordHasher\DefaultPasswordHasher;
$hasher = new DefaultPasswordHasher();
使用这个:
use Cake\Auth\DefaultPasswordHasher as AuthDefaultPasswordHasher;
$hasher = new AuthDefaultPasswordHasher();
请使用这个:
protected function _setPassword($value) {
return sha1($value);
}