setCredentialTreatment($credentialTreatment); } } /** * setCredentialTreatment() - allows the developer to pass a parametrized string that is * used to transform or treat the input credential data. * * In many cases, passwords and other sensitive data are encrypted, hashed, encoded, * obscured, or otherwise treated through some function or algorithm. By specifying a * parametrized treatment string with this method, a developer may apply arbitrary SQL * upon input credential data. * * Examples: * * 'PASSWORD(?)' * 'MD5(?)' * * @param string $treatment * @return DbTable Provides a fluent interface */ public function setCredentialTreatment($treatment) { $this->credentialTreatment = $treatment; return $this; } /** * _authenticateCreateSelect() - This method creates a Zend\Db\Sql\Select object that * is completely configured to be queried against the database. * * @return Sql\Select */ protected function authenticateCreateSelect() { // build credential expression if (empty($this->credentialTreatment) || (strpos($this->credentialTreatment, '?') === false)) { $this->credentialTreatment = '?'; } $credentialExpression = new SqlExpr( '(CASE WHEN ?' . ' = ' . $this->credentialTreatment . ' THEN 1 ELSE 0 END) AS ?', array($this->credentialColumn, $this->credential, 'zend_auth_credential_match'), array(SqlExpr::TYPE_IDENTIFIER, SqlExpr::TYPE_VALUE, SqlExpr::TYPE_IDENTIFIER) ); // get select $dbSelect = clone $this->getDbSelect(); $dbSelect->from($this->tableName) ->columns(array('*', $credentialExpression)) ->where(new SqlOp($this->identityColumn, '=', $this->identity)); return $dbSelect; } /** * _authenticateValidateResult() - This method attempts to validate that * the record in the resultset is indeed a record that matched the * identity provided to this adapter. * * @param array $resultIdentity * @return AuthenticationResult */ protected function authenticateValidateResult($resultIdentity) { if ($resultIdentity['zend_auth_credential_match'] != '1') { $this->authenticateResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; $this->authenticateResultInfo['messages'][] = 'Supplied credential is invalid.'; return $this->authenticateCreateAuthResult(); } unset($resultIdentity['zend_auth_credential_match']); $this->resultRow = $resultIdentity; $this->authenticateResultInfo['code'] = AuthenticationResult::SUCCESS; $this->authenticateResultInfo['messages'][] = 'Authentication successful.'; return $this->authenticateCreateAuthResult(); } }