【发布时间】:2014-05-11 20:49:43
【问题描述】:
我使用的是 Cakephp 2.4,但我在使用 Auth 进行简单身份验证时遇到了问题。
我使用数据库中的“邮件”列作为登录名。
我做什么:
在 AppController.php 中
public $components = array('DebugKit.Toolbar', 'Session', 'Auth' => array(
'loginAction' => array(
'controller' => 'users',
'action' => 'login',
'plugin' => false
),
'authError' => 'Pensiez-vous réellement que vous étiez autorisés à voir cela ?',
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'mail')
)
)
));
在 UsersController.php 中
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(
__('Username ou password est incorrect'),
'default',
array(),
'auth'
);
}
}
}
在 login.ctp
<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User');?>
<fieldset>
<legend><?php echo __('Merci de rentrer votre nom d\'user et mot de passe'); ?></legend>
<?php echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Connexion'));?>
</div>
我尝试使用清晰的散列密码,但每次他都不让我登录。
【问题讨论】:
-
大声笑,我只是尝试一些新的东西,我给登录功能 $this->request->data 并且他做一些事情,如果有人可以告诉我这是否是好方法?跨度>
-
好吧,这可能不是好方法,因为登录功能对每个密码都返回 true。
标签: php cakephp authentication cakephp-2.4