【发布时间】:2014-11-28 07:00:18
【问题描述】:
我坚持认为我的 cakephp 登录不起作用。我正在同一视图上创建登录和注册。期待帮助。这是我的代码。
public function login(){
(isset($this->request->data['User'])) { // Check if the login Form was submitted
if (!empty($this->request->data['User']) && $this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
$this->request->data['User']['password'] = '';
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
这个函数的模型是
class User extends AppModel{
public $validate = array(
'email'=>'email',
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
)
),);
观点是:
<div><?php echo $this->Session->flash(); ?></div>
<?php echo $this->Form->create("User"); ?>
<?php echo $this->Form->input('email' ,array('label'=>"Email :")); ?>
<?php echo $this->Form->input('password',array('label'=>"Password"));?>
<?php echo $this->Form->end('Login'); ?>
哈希密码使用注册正确保存在数据库中,但是当我在登录时输入密码时,它给出了无效的用户名和密码错误。 我的 AppController 是
class AppController extends Controller {
public $components = array(
'Auth'=> array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' =>'email','password'=>'password')
)
)
),
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'users',
'action' => 'profileindex'
),
//'authorize' => array('Controller'),
'loginAction' => array('controller' => 'users', 'action' => 'login'),
'loginRedirect' => array('controller' => 'users', 'action' => 'profileindex'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authError' => 'You don\'t have access here.',
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login',
'home'
),
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish'
)
)
)
);
【问题讨论】:
-
首先在数据库中使用加密形式的密码。
-
密码加密存储在数据库中。
-
我已经做到了兄弟,我是这个 cakephp 的新手,所以我想我错过了一些东西。
-
遇到同样的问题你找到解决办法了吗
标签: cakephp