当我尝试登录时说"无效的电子邮件或密码,请再试一次"。我使用了默认密码hasher而没有它也可以,但我得到的结果与两者相同。并且默认验证也不起作用。 登录代码。
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
//pr($user);die;
if ($user) {
$this->Auth->setUser($user);
if ($this->Auth->authenticationProvider()->needsPasswordRehash()) {
$user = $this->Users->get($this->Auth->user('id'));
$user->password = $this->request->data('password');
$this->Users->save($user);
}
return $this->redirect($this->Auth->redirectUrl());
}
else {
$this->Flash->error(__('Username or password is incorrect'),'default',[],'auth');
}
}
}
验证代码。
// src/Model/Table/UsersTable.php
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class UsersTable extends Table
{
public function validationDefault(Validator $validator)
{
return $validator
->notEmpty('email', 'A email is required')
->notEmpty('password', 'A password is required')
;
}
}
如果有人需要更多信息,请告诉我。 提前谢谢。