【问题标题】:Two kind of authetication in cake PHP- by different cross fieldcakePHP中的两种身份验证-通过不同的交叉字段
【发布时间】:2012-08-24 11:28:03
【问题描述】:

在我的应用程序中,我需要首先通过用户名和密码(都是数据库字段)通过两种方式检查用户身份验证, cake php 已经给了这个

  $this->Auth->fields = array(
        'username' => 'username', 
        'password' => 'password'
        );

现在我需要的是,如果在第一种情况下用户无法进行身份验证,那么检查用户名和 forgot_password 的用户数据(两者都是数据库字段) 为此,我该如何使用 Auth 组件字段?我试过了:

else
{
$this->Auth->fields = array(
        'username' => 'username', 
        'password' => 'forgot_password'
        );
$this->Auth->login();       
}

但这不起作用..还有其他方法吗? 我需要两种类型的交叉检查条件。

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    你应该使用$this->Auth->constructAuthenticate();

    <?php
    function login()
    {       
        if ($this->request->is('post'))
        {
            if (!$this->Auth->login())
            {
                $this->Auth->authenticate = array('Form' => array('fields' => array('username' => 'username',
                                                    'password' => 'forgot_password')));
                $this->Auth->constructAuthenticate();
                if ($this->Auth->login())
                {
                    //Your message here
                    //redirect to further pages
                }
                else
                {
                    //redirect to login page
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 2020-12-23
      • 1970-01-01
      • 2011-03-11
      • 2011-07-31
      • 1970-01-01
      • 2012-05-22
      相关资源
      最近更新 更多