Cakephp 3.0 错误:Class';App\Model\Entity\DefaultPasswordHasher';找不到
我缺少以下行:Cakephp 3.0 错误:Class';App\Model\Entity\DefaultPasswordHasher';找不到,cakephp-3.0,Cakephp 3.0,我缺少以下行: <?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 al
<?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);
}
}
这就是我出错的原因。请使用以下命令:
use Cake\Auth\DefaultPasswordHasher;
如果您使用的是cakephp 4.0版和 已经在php文件中包含了这两个用于密码哈希的函数
protected function _setPassword($value) {
return sha1($value);
}
正如官方cakephp 4.0文档中提到的:-
但仍然会出现如下错误:-
use Authentication\PasswordHasher\DefaultPasswordHasher;
{
$hasher = new DefaultPasswordHasher();
return $hasher->hash($password);
}
然后,不要使用:-
Undefined type 'Authentication\PasswordHasher\DefaultPasswordHasher'. intelephense(1009) [50,23]
使用以下命令:-
use Authentication\PasswordHasher\DefaultPasswordHasher;
$hasher = new DefaultPasswordHasher();
我在那一行得到了
错误:语法错误,意外的“?”
。有什么线索吗?@JackTheKnife检查你的语法。虽然你可能没有处理高安全性的问题,但值得注意的是,sha1现在被认为已被泄露(例如)
use Cake\Auth\DefaultPasswordHasher as AuthDefaultPasswordHasher;
$hasher = new AuthDefaultPasswordHasher();