Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom function to validate the password hash (wa_password_verify) #348

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wa-system/auth/waAuth.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ protected function isOnetimePasswordMode()
protected function _authByPassword($contact, $password)
{
$contact_password = isset($contact['password']) && is_scalar($contact['password']) ? $contact['password'] : '';
return strlen($contact_password) > 0 && waContact::getPasswordHash($password) === $contact_password;
return strlen($contact_password) > 0 && waContact::verifyPasswordHash($password, $contact_password);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions wa-system/contact/waContact.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,25 @@ public static function getPasswordHash($password)
}
}

/**
* Verifies the password hash.
*
* By default, strict comparison is used. If configuration file wa-config/SystemConfig.class.php
* contains information about user-defined function wa_password_verify(), then that function is used for hash verification.
*
* @param string$password
* @param string $hash
* @return bool
*/
public static function verifyPasswordHash($password, $hash)
{
if (function_exists('wa_password_verify')) {
return (bool) wa_password_verify($password, $hash);
} else {
return waContact::getPasswordHash($password) === $hash;
}
}

/**
* @param int $len
* @param bool $extended - use extended alphabet or only letters and digits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ protected function isSecretEquals($input_secret, $asset_secret, $asset_name)
if ($asset_name === waVerificationChannelAssetsModel::NAME_PASSWORD_RECOVERY_HASH || $asset_name === waVerificationChannelAssetsModel::NAME_SIGNUP_CONFIRM_HASH) {
return $input_secret === $asset_secret;
} else {
return waContact::getPasswordHash($input_secret) === $asset_secret;
return waContact::verifyPasswordHash($input_secret, $asset_secret);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected function isAddressEquals($address1, $address2)

protected function isSecretEquals($input_secret, $asset_secret, $asset_name)
{
return waContact::getPasswordHash($input_secret) === $asset_secret;
return waContact::verifyPasswordHash($input_secret, $asset_secret);
}


Expand Down