我使用CakePHP的最後一個版本(2.5.4,如果我是對的)&我嘗試登錄時遇到問題。CakePHP登錄不認證
我有一張名爲「Accounts」的表,&我的控制器被稱爲「UsersController.php」,model =>「User.php」等。似乎沒有問題,因爲我設置了默認表「賬戶」。我已經提出了註冊的意見,並且我正在使用md5來散列密碼,並且它工作的很好。
但是,當我想登陸,它始終返回false &它不記錄我
這裏是UsersController.php我的登錄功能:
function login(){
if($this->request->is('post'))
{
if($this->Auth->login())
{
$this->Session->setFlash("Vous êtes maintenant connecté !", "notif");
$this->redirect('/');
} else {
$this->Session->setFlash("Les identifiants sont incorrects", "notif", array('type' => 'danger'));
debug(Security::hash($this->request->data['User']['PasswordHash']));
}
}
}
這裏是形式從login.ctp:
<?= $this->Form->input('Login', array('placeholder' => 'Login', 'label' => false)); ?>
<b class="tooltip tooltip-bottom-right">Votre nom de compte</b>
</label>
</section>
<section>
<label class="input">
<i class="icon-append fa fa-lock"></i>
<?= $this->Form->input('PasswordHash', array('placeholder' => 'Mot de passe', 'label' => false)); ?>
<b class="tooltip tooltip-bottom-right">Votre mot de passe!</b>
</label>
</section>
</fieldset>
<fieldset>
<section>
<h4>Mot de passe perdu ?</h4>
<p><a style='color:#009900' href="#">Cliquez ici</a> pour réinitialiser le mot de passe.</p>
</section>
</fieldset>
<footer>
<center>
<?php $options = array(
'class' => 'btn-u',
'label' => 'Connexion'
) ?>
<?= $this->form->end($options); ?>
我忘了提,我的專欄不是USERNAME &密碼,而是登錄& PasswordHash
而且,這裏是我的AppController.php:
class AppController extends Controller {
public $components = array(
'Session',
'Cookie',
'Auth');
function beforeFilter(){
Security::setHash('md5');
$this->Auth->allow();
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array('username' => 'Login', 'password' => 'PasswordHash'),
)
);
}
}
我無法登錄,我不明白爲什麼。我的請求查詢如下所示:
SELECT `User`.`Id`, `User`.`Login`, `User`.`PasswordHash`, `User`.`Nickname`, `User`.`Role`, `User`.`AvailableBreeds`, `User`.`Ticket`, `User`.`SecretQuestion`, `User`.`SecretAnswer`, `User`.`Lang`, `User`.`Email`, `User`.`CreationDate`, `User`.`Tokens`, `User`.`NewTokens`, `User`.`LastVote`, `User`.`RecordVersion` FROM `madara`.`accounts` AS `User` WHERE `User`.`Login` = 'Twoast' LIMIT 1
調試顯示我與我的表帳戶中的哈希相同。我不確定我做錯了什麼。
在此先感謝!
你檢查了你的服務器上的PHP錯誤日誌? – 2014-09-30 20:15:27
我的PHP錯誤日誌中沒有任何東西,似乎沒有錯誤,請求看起來很棒,但它不需要。該死...... – Twoast 2014-10-01 11:22:26
你有沒有機會登錄? _(我認爲如果你已經登錄,'login'返回false。)_我的登陸方法首先檢查'$ this-> Auth-> loggedIn()'在任何其他事務處理之前是否爲false。 – AgRizzo 2014-10-01 13:49:38