On this ticket, CakePHP Member Mark Story mentions that bcrypt will be supported in CakePHP 2.3 (not yet released) and will become standard / default in 3.0.
In addition, in this blog post, Mark talks about what changes are needed to use bcrypt in CakePHP 2.0. This is relatively minor, although changes will be required for your user model.
Borrowing the code from this post, what Mark did was subclass FormAuthenticate:
<?php App::uses('FormAuthenticate', 'Controller/Component/Auth'); class BcryptFormAuthenticate extends FormAuthenticate { public static $cost = 10; protected function _password($password) { return self::hash($password); } public static function hash($password) { $salt = substr(Configure::read('Security.salt'), 0, 22); return crypt($password, '$2a$' . self::$cost . '$' . $salt); } }
Then an update was made to the array of controller components:
<?php public $components = array( 'Auth' => array( 'authenticate' => 'BcryptForm',
And finally, updating the beforeSave
user model beforeSave
:
<?php App::uses('BcryptFormAuthenticate', 'Controller/Component/Auth'); class User extends AppModel { function beforeSave() { if (isset($this->data['User']['password'])) { $this->data['User']['password'] = BcryptFormAuthenticate::hash($this->data['User']['password']); } return true; } }
source share