CakePHP登录不进行身份验证
如果我是对的,我使用的是cakephp2.5.4的最新版本&我在尝试登录时遇到了问题 我有一个名为Accounts的表,我的控制器名为UsersController.php、model=>User.php等。这似乎没有问题,因为我将默认表设置为Accounts。我已经提出了注册的想法,我正在使用md5散列密码,它工作得非常好 但是,当我想登录时,它总是返回false&它不会让我登录 以下是我在UsersController.php中的登录函数:CakePHP登录不进行身份验证,php,mysql,cakephp,login,Php,Mysql,Cakephp,Login,如果我是对的,我使用的是cakephp2.5.4的最新版本&我在尝试登录时遇到了问题 我有一个名为Accounts的表,我的控制器名为UsersController.php、model=>User.php等。这似乎没有问题,因为我将默认表设置为Accounts。我已经提出了注册的想法,我正在使用md5散列密码,它工作得非常好 但是,当我想登录时,它总是返回false&它不会让我登录 以下是我在UsersController.php中的登录函数: function login(){
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']));
}
}
}
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'),
)
);
}
这是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); ?>
}
我不能登录,我不明白为什么。我的请求查询如下所示:
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个字符。因此,3天后,我终于找到了解决方案 我的功能登录变成:
function login(){
if($this->request->is('post'))
{
$data = $this->request->data;
$Logined = $this->request->data['User']['Login'];
$PasswordHashed = Security::hash($data['User']['PasswordHash'], 'md5', false);
$user = $this->User->find('first', array(
'conditions' => array(
'User.Login' => $Logined,
'User.PasswordHash' => $PasswordHashed
),
'recursive' => -1
));
if(!empty($user) && $this->Auth->login($user['User'])) {
$this->Session->setFlash("Vous êtes maintenant connecté !", "notif");
$this->redirect('/');
} else {
$this->Session->setFlash("Les identifiants sont incorrects", "notif", array('type' => 'danger'));
}
}
}
所以,这个功能工作得很好,它只需要手动登录
谢谢你的帮助!: 你检查过服务器上的php错误日志了吗?我的php错误日志中没有任何内容,似乎没有错误,请求看起来很好,但它不想要。该死…你有没有可能已经登录了?如果您已经登录,我认为登录返回false。我的登录方法首先检查$this->Auth->loggedIn是否为false,然后再处理任何其他内容。这应该是一条注释而不是答案。是的,它足够长45个字符&我不理解为什么字段PasswordHash的调试与数据库中我的PasswordHash值完全匹配。我还不能对帖子进行注释,所以我必须发布一个答案。正如我所说,我将数据库中密码字段的大小更改为128,并为我修复了它。