zend-frameworkzend-auth

Add condition for Zend_Auth_Adapter_DbTable


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();
    }

Solution

  • 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');