加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何替换cakephp密码哈希算法?

发布时间:2020-12-13 14:13:53 所属栏目:PHP教程 来源:网络整理
导读:我有一个现有的数据库,我正试图把蛋糕应用程序放在上面.旧的应用程序在Perl中使用crypt()来散列密码.我需要在 PHP应用程序中执行相同的操作. 在标准的cakephp应用程序中进行更改的正确位置在哪里?这样的改变会是什么样的? 我搞定了…… 这是我的AppControl
我有一个现有的数据库,我正试图把蛋糕应用程序放在上面.旧的应用程序在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/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读