错误:找不到类'AppModelEntityDefaultPasswordHasher'


<?php
namespace AppModelEntity;
use CakeORMEntity;
/**
 * 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中的代码。我正在对密码进行哈希处理,结果出现了这个错误

错误:类"AppModelEntityDefaultPasswordHasher"未找到文件C:xamphtdocsbookmarkersrcModelEntityUser.php Line: 27

我缺少了以下一行:

use CakeAuthDefaultPasswordHasher;

如果您使用cakephp version 4.0和已经在PHP文件中包含了这两个用于密码散列:

use AuthenticationPasswordHasherDefaultPasswordHasher;

{
    $hasher = new DefaultPasswordHasher();
    return $hasher->hash($password);
}

在官方cakephp 4.0 documentation中提到

仍然得到这样的错误:

Undefined type 'AuthenticationPasswordHasherDefaultPasswordHasher'. 
intelephense(1009) [50,23]

.

然后不用:

 use AuthenticationPasswordHasherDefaultPasswordHasher;
   
 $hasher = new DefaultPasswordHasher();
使用

:

 use CakeAuthDefaultPasswordHasher as AuthDefaultPasswordHasher;
 $hasher = new AuthDefaultPasswordHasher();

请使用:

protected function _setPassword($value) {
    return sha1($value);
}

相关内容

最新更新