在cakephp中已经从simplePasswordHasher变为BlowfishPasswordHasher。我添加以下代码并注释掉旧的simplehasher方法的所有引用,但我无法登录。我可以使用BlowfishPasswordHasher创建一个新用户,但登录现在不起作用了吗?
下面的链接没有解决问题,因为我无法登录,但我可以看到新用户使用正确的盐渍密码
CakePHP - How do I implement blowfish hashing for passwords?
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html
//userscontroller
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl()); //for 2.3 and above versions, docs are old
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
//user
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new BlowfishPasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash(
$this->data[$this->alias]['password']
);
}
return true;
}
//new user
<?php echo $this->Form->create('User'); ?>
<h2><?php echo __('Add User2'); ?></h2>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password');
public function beforeFilter(){
$this->Auth->authError = 'You cant access this page';
$this->Auth->loginRedirect= array('controller' => 'users', 'action' => 'dashboard');
$this->Auth->logoutRedirect= array('controller' => 'users','action' => 'login' );
$this->Auth->authorize= array('Controller');
$this->Auth->unauthorizedRedirect= '/users/dashboard';
$this->set("logged_in", $this->Auth->loggedIn())
//user model
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
)
),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
)
)