我的問題是我有一個不同的用戶表模型名稱:飼養員。我的登錄頁面總是說不正確的用戶名或密碼,因爲輸入的密碼沒有被散列。Cakephp身份驗證:2.4.2
這裏是視圖:
<?php
echo $this->Form->create();
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Log in');
echo $this->Html->link('Register', '/breeders/register');
?>
這裏是AppController的:
類AppController的延伸控制器{
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session', 'Paginator',
'Auth' => array(
'loginAction' => array('controller' => 'breeders', 'action' => 'login'),
'loginRedirect' => array('controller' => 'breeders', 'action' => 'desk'),
'logoutRedirect' => array('controller' => 'breeders', 'action' => 'login'),
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'login',
'password' => 'password'),
'passwordHasher' => array(
'className' => 'Simple',
'hashType' => 'sha256'
)
)
)
)
);
public function isAuthorized($user)
{
return true;
}
public function beforeFilter() {
$this->Auth->allow('login', 'logout', 'register', 'profile');
}
}
我的登錄方法:
public function login() {
$this->set('title_for_layout', __('Connection'));
if ($this->Session->read('Auth.Breeder')) {
return $this->redirect('/');
}
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
}
}
}
的d的beforeSave方法模型:
public function beforeSave($options = array()) {
if (!$this->id) {
$passwordHasher = new SimplePasswordHasher();
$this->data['Breeder']['password'] = $passwordHasher->hash(
$this->data['Breeder']['password']
);
}
return true;
}
我不知道我需要添加到使密碼被散列。任何幫助將受到歡迎。
看來,我已經在採取它關閉測試幾種可能性,但我曾嘗試過。現在我只是添加它,因爲我的登錄函數工作(我手動散列密碼,所以它應該哈希兩次)我想這不是解決方案。不管怎樣,謝謝你 – Charline