Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Custom password checker for database adapter #3371

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions library/Zend/Authentication/Adapter/DbTable.php
Expand Up @@ -102,6 +102,12 @@ class DbTable implements AdapterInterface
*/
protected $ambiguityIdentity = false;

/**
* Closure for custom password checker
* @val Closure
*/
protected $passwordChecker = null;

/**
* __construct() - Sets configuration options
*
Expand Down Expand Up @@ -303,6 +309,27 @@ public function getResultRowObject($returnColumns = null, $omitColumns = null)
return $returnObject;
}


/**
* Set the password checker callback
* @param Closure $callback
*/
public function setPasswordChecker( $callback ) {

if(!is_callable($callback)) {
throw new \InvalidArgumentException("Password checker must be callable");
}

$this->passwordChecker = $callback;
}

/**
* Get the password cehcker closure
*/
public function getPasswordChecker() {
return $this->passwordChecker;
}

/**
* This method is called to attempt an authentication. Previous to this
* call, this adapter would have already been configured with all
Expand Down Expand Up @@ -459,6 +486,13 @@ protected function _authenticateValidateResultSet(array $resultIdentities)
*/
protected function _authenticateValidateResult($resultIdentity)
{
if($this->passwordChecker != null) {
$callback = $this->passwordChecker;
if ($callback($resultIdentity[$this->credentialColumn], $this->credential)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use call_user_func(), as not all Callable items may be called using function call syntax (e.g., static and instance methods).

$resultIdentity['zend_auth_credential_match'] = '1';
}
}

if ($resultIdentity['zend_auth_credential_match'] != '1') {
$this->authenticateResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID;
$this->authenticateResultInfo['messages'][] = 'Supplied credential is invalid.';
Expand Down