Having a bit of trouble getting cakephp to authenticate against a blowfish stored password.
In AppController. Setup global compnents. User Model is CompaniesUser, which corresponds to a file on disk called CompaniesUser.php. Password Hasher is Blowfish
App::uses('AuthComponent', 'Controller/Component');
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
class AppController extends Controller {
public $helpers = array('CustomHtml');
public $components = array(
'DebugKit.Toolbar',
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'dashboard',
'action' => 'something'
),
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login'
),
'authenticate' => array(
'Form' => array(
'userModel' => 'CompaniesUser',
'passwordHasher' => 'Blowfish'
)
)
)
);
Login CTP:
<?php
echo $this->Form->create('User', array('action' => 'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');
?>
CompaniesUser Model before the Item is saved:
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 database does indeed appear to have the blowfished password in place.
UsersController.php where the login method lives..
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
class UsersController extends AppController {
public $uses = array(
'Company','CompaniesUser'
);
public function login()
{
//uses a different theme
$this->layout = 'admin\login';
if ($this->request->is('post')) {
if ( $this->Auth->login() )
return $this->redirect( $this->Auth->redirectUrl() );
$this->Session->setFlash( __( Configure::read('UsersController.InvalidPassword') ), 'custom\flash' );
}
}
public function beforeFilter()
{
parent::beforeFilter();
$this->Auth->authenticate = array(
'Basic' => array('userModel' => 'CompaniesUser'),
'Form' => array('userModel' => 'CompaniesUser')
);
// Allow users to register and logout.
$this->Auth->allow('register', 'logout', 'verify', 'verifyResend', 'verifyAuth');
}
Cake still refuses to login, and considering $this->Auth->login() is something of a black box, I can't see what SQL output currently looks like. I've tried some of the guidance on using DebugKit, currently reports: Sql Logs
Warning No active database connections. <-- now returning SQL having changed the form name.
Anyone any ideas on things to try?
UPDATE: SQL coming back from the login form looks like this.
SELECT `CompaniesUser`.`id`, `CompaniesUser`.`company_id`, `CompaniesUser`.`name`, `CompaniesUser`.`username`
, `CompaniesUser`.`password`, `CompaniesUser`.`active`, `CompaniesUser`.`user_activation_hash`, `CompaniesUser`.`user_password_reset_hash`, `CompaniesUser`.`user_password_reset_timestamp`, `CompaniesUser`.`holidays_allocated`, `CompaniesUser`.`admin`, `CompaniesUser`.`manager`, `CompaniesUser`.`first_run_finished`, `CompaniesUser`.`payment_active`, `Company`.`id`, `Company`.`name`, `Company`.`account_type`, `Company`.`active`, `Company`.`stripe_customer_id`, `Company`.`payment_active`
FROM `deckchair`.`companies_users` AS `CompaniesUser`
LEFT JOIN `deckchair`.`companies` AS `Company`
ON (`CompaniesUser`.`company_id` = `Company`.`id`)
WHERE `CompaniesUser`.`username` = 'user@test.com' LIMIT 1