Add Condition for Zend_Auth_Adapter_DbTable

This may seem like a silly question, but in this code, wherever 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(); } 
+4
source share
2 answers

Based on the example in the zf manual, I would say that you can add AND state=1 to your setCredentialTreatment () method:

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

For those who are hoping for this post. There is a better way to check the status in the same table where authentication occurs:

Another alternative is to use the getDbSelect () method of Zend_Auth_Adapter_DbTable after the adapter has been created. This method will return an instance of the Zend_Db_Select object, which it will use to complete the authenticate () procedure.

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

0
source

All Articles