4

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();
    }
Moak
  • 12,596
  • 27
  • 111
  • 166

2 Answers2

9

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');
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • the where condition is not working for me. I am trying `->setCredentialTreatment('verified="Y"');` according to the docs, we cannot pass where conditions like this - [doc link](http://framework.zend.com/apidoc/1.0/Zend_Auth/Zend_Auth_Adapter/Zend_Auth_Adapter_DbTable.html) – Raj Jun 07 '11 at 06:39
0

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