【问题标题】:CakePHP autentication with auth table other than User problemCakePHP 身份验证与用户问题以外的身份验证表
【发布时间】:2011-05-16 10:28:29
【问题描述】:

我在开发 cakephp 身份验证方面遇到了很多问题。为此,我正在尝试使用名为reviewers 的表,其中当然包含用户名和密码字段。

我检查了,并从登录表单发送了正确的数据(用户名和密码)。

文件 app_controller.php 包含:

    class AppController extends Controller {
var $components = array('Auth', 'Session', 'Cookie', 'P28n');

    function beforeFilter() {

        $this->Auth->authenticate = ClassRegistry::init('Reviewer');

        Security::setHash('sha1'); // or sha1 or sha256
        $this->Auth->userModel = 'Reviewers';
    $this->Auth->fields = array('username' => 'username', 'password'=>'password');
    $this->Auth->loginRedirect = array('controller' => 'reviewers', 'action' => 'view');

    } 

如何检查和调试问题?我得到的错误是用户名和密码组合不正确。

让我抓狂的是,我之前已经开发过类似的功能,而且运行起来没有问题........

请帮忙。

更新:使用 cakephp 调试工具,似乎从未调用过 auth 组件。

【问题讨论】:

  • 您是否在某个地方的控制器中覆盖了您的 beforeFilter() 函数?确保调用 parent::beforeFilter();

标签: authentication cakephp cakephp-1.3


【解决方案1】:

我在 Cake 1.3 中也遇到过类似的问题,似乎 Auth 组件的自动散列不同于您保存用户时进行的散列。

我最终得到了这个解决方案: 我已经在保存之前在用户控制器中添加了这个。

$this->data['User']['password'] = Security::hash($this->data['User']['password']);

现在它工作正常......也许这会有所帮助。

【讨论】:

  • 不,还是一样。但是,让我感到困惑的是,如果打开调试,我无法在创建 cakephp 的 sql 转储中看到 sql 查询。所以,对我来说,似乎根本没有调用身份验证控制器。
【解决方案2】:

如果你尝试$this->Auth->authenticate =& ClassRegistry::init('Reviewer') 来获取对象的引用会怎样。

AuthComponent - authenticate Property

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-12
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    相关资源
    最近更新 更多