I'm new to CakePHP, and I'm using version 2.8.5. I have followed the tutorial for adding authentication to my website as is here: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html, but I am having problems trying to login.
I can add new users, but whenever I try to login it returns false and I get:
Invalid username or password, try again.
I also get:
Warning (512): Invalid salt: pass01 for blowfish Please visit http://www.php.net/crypt and read the appropriate section for building blowfish salts. [CORE/Cake/Utility/Security.php, line 323]
(pass01 is the password). I have followed the instructions of the tutorial exactly with regards to the blowfish hashing, but the passwords in my database don't appear to be hashed (they just appear as they are).
User.php
App::uses('AppModel', 'Model');
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
class User extends AppModel {
public $validate = array(
'username' => array(
'required' => array(
'rule' => 'notBlank',
'message' => 'A username is required'
)
),
'password' => array(
'required' => array(
'rule' => 'notBlank',
'message' => 'A password is required'
)
),
'role' => array(
'valid' => array(
'rule' => array('inList', array('admin', 'author')),
'message' => 'Please enter a valid role',
'allowEmpty' => false
)
)
);
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;
}
}
The login function from UsersController.php
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}
login.ctp
<div class="users form">
<?php echo $this->Flash->render('auth'); ?>
<?php echo $this->Form->create('User'); ?>
<fieldset>
<legend>
<?php echo __('Please enter your username and password'); ?>
</legend>
<?php echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>
I have looked around all the similar questions, but none of the solutions seem to have worked for me. I would really appreciate any help with this.