为 Zend_Auth_Adapter_DbTable 添加条件

发布于 2024-11-07 07:42:25 字数 793 浏览 0 评论 0原文

这似乎是一个愚蠢的问题,但在这段代码中,我将在哪里插入条件 'WHERE state=1'

    public function loginByUsernameAndPassword($username, $password)
    {   
        $this->_auth_adapter = new Zend_Auth_Adapter_DbTable( $this->getAdapter() );
        $this->_auth_adapter->setTableName('zend_administration_user')
                            ->setIdentityColumn('user_nm')
                            ->setCredentialColumn('password')
                            ->setCredentialTreatment('SHA1(CONCAT(?,salt))');
        $this->_auth_adapter->setIdentity($username)
                            ->setCredential($password);
        $result = Zend_Auth::getInstance()->authenticate($this->_auth_adapter);
        return $result->isValid();
    }

This may seem like a silly question, but in this code, where would I insert the condition 'WHERE state=1'

    public function loginByUsernameAndPassword($username, $password)
    {   
        $this->_auth_adapter = new Zend_Auth_Adapter_DbTable( $this->getAdapter() );
        $this->_auth_adapter->setTableName('zend_administration_user')
                            ->setIdentityColumn('user_nm')
                            ->setCredentialColumn('password')
                            ->setCredentialTreatment('SHA1(CONCAT(?,salt))');
        $this->_auth_adapter->setIdentity($username)
                            ->setCredential($password);
        $result = Zend_Auth::getInstance()->authenticate($this->_auth_adapter);
        return $result->isValid();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌若浮生 2024-11-14 07:42:25

基于 在 zf 手册中的示例中,我想说您可以将 AND state=1 添加到 setCredentialTreatment() 方法中:

->setCredentialTreatment('SHA1(CONCAT(?,salt)) AND state = 1');

Based on an example in the zf manual, I would say you could add AND state=1 into your setCredentialTreatment() method:

->setCredentialTreatment('SHA1(CONCAT(?,salt)) AND state = 1');
喜爱纠缠 2024-11-14 07:42:25

对于那些希望进入这篇文章的人。有更好的方法来验证发生身份验证的同一个表中的条件:

另一种选择是使用 getDbSelect() 方法
构造适配器后的 Zend_Auth_Adapter_DbTable。这
方法将返回 Zend_Db_Select 对象实例,它将用于
完成authenticate()例程。

对于上面的示例:

$select = $this->_auth_adapter->getDbSelect();
$select->where('state = 1');

// authenticate, this ensures that zend_administration_user.state = 1
$adapter->authenticate();

来源:http://framework. zend.com/manual/1.12/en/zend.auth.adapter.dbtable.html

For those who hope into this post. There is better way to validate a condition within the same table where the authentication happens:

Another alternative is to use the getDbSelect() method of the
Zend_Auth_Adapter_DbTable after the adapter has been constructed. This
method will return the Zend_Db_Select object instance it will use to
complete the authenticate() routine.

For the example above:

$select = $this->_auth_adapter->getDbSelect();
$select->where('state = 1');

// authenticate, this ensures that zend_administration_user.state = 1
$adapter->authenticate();

Source: http://framework.zend.com/manual/1.12/en/zend.auth.adapter.dbtable.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文