Skip to content

Instantly share code, notes, and snippets.

@s7anley
Created November 17, 2015 22:35
Show Gist options
  • Select an option

  • Save s7anley/b497c7cd05dec10ee75f to your computer and use it in GitHub Desktop.

Select an option

Save s7anley/b497c7cd05dec10ee75f to your computer and use it in GitHub Desktop.

Revisions

  1. s7anley created this gist Nov 17, 2015.
    36 changes: 36 additions & 0 deletions Zend_Auth_Adapter_BcryptDbTable.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <?php

    class Base_Auth_Adapter_BcryptDbTable extends Zend_Auth_Adapter_DbTable
    {
    /**
    * @inheritdoc
    */
    protected function _authenticateCreateSelect()
    {
    $dbSelect = clone $this->getDbSelect();
    $dbSelect->from($this->_tableName)
    ->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity);

    return $dbSelect;
    }

    /**
    * @inheritdoc
    */
    protected function _authenticateValidateResult($resultIdentity)
    {
    $passwordCheck = password_verify($this->_credential, $resultIdentity[$this->_credentialColumn]);

    if (!$passwordCheck) {
    $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
    $this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.';
    return $this->_authenticateCreateAuthResult();
    }

    $this->_resultRow = $resultIdentity;

    $this->_authenticateResultInfo['code'] = Zend_Auth_Result::SUCCESS;
    $this->_authenticateResultInfo['messages'][] = 'Authentication successful.';
    return $this->_authenticateCreateAuthResult();
    }
    }