我正在使用最新版本的 CakePHP(如果我没记错的话是 2.5.4)并且我在尝试登录时遇到了问题。
我有一个名为“Accounts”的表,我的 Controller 名为“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); ?>
我忘了说我的列不是用户名和密码,而是登录名和密码哈希
此外,这是我的 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
调试向我显示了与我的表 Accounts 中相同的哈希值。我不确定我做错了什么。
提前致谢!
最佳答案
您将表中的密码字段设置为多大?是否足够长以适合哈希字段?我以前有过这个,必须将其设置为至少 50 个字符。
关于php - CakePHP 登录未通过身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26129086/