我有一个现有的数据库,我正试图把蛋糕应用程序放在上面.旧的应用程序在Perl中使用crypt()来散列密码.我需要在
PHP应用程序中执行相同的操作.
在标准的cakePHP应用程序中进行更改的正确位置在哪里?这样的改变会是什么样的?
我搞定了……
这是我的AppController:
class AppController extends Controller {
var $components = array('Auth');
function beforeFilter() {
// this is part of cake that serves up static pages,it should be authorized by default
$this->Auth->allow('display');
// tell cake to look on the user model itself for the password hashing function
$this->Auth->authenticate = ClassRegistry::init('User');
// tell cake where our credentials are on the User entity
$this->Auth->fields = array(
'username' => 'user','password' => 'pass',);
// this is where we want to go after a login... we'll want to make this dynamic at some point
$this->Auth->loginRedirect = array('controller'=>'users','action'=>'index');
}
}
然后这是用户:
<?PHP
class User extends AppModel {
var $name = 'User';
// this is used by the auth component to turn the password into its hash before comparing with the DB
function hashPasswords($data) {
$data['User']['pass'] = crypt($data['User']['pass'],substr($data['User']['user'],2));
return $data;
}
}
?>
我认为其他一切都很正常.
这是一个很好的资源:http://teknoid.wordpress.com/2008/10/08/demystifying-auth-features-in-cakephp-12/