Back to MD5Handler class

Method validatePassword

public bool
validatePassword
(mixed $plaintext, mixed $hashed)
Validate a password
Parameters
  • string $pla intext The plain text password to validate
  • string $hashed The password hash to validate against
Returns
  • bool
Since
  • 4.0.0
Class: MD5Handler
Project: Joomla

Method validatePassword - Source code

/**
 * Validate a password
 *
 * @param   string  $plaintext  The plain text password to validate
 * @param   string  $hashed     The password hash to validate against
 *
 * @return  boolean
 *
 * @since   4.0.0
 */
public function validatePassword($plaintext, $hashed)
{
    // Check the password
    $parts = explode(':', $hashed);
    $salt = @$parts[1];
    // Compile the hash to compare
    // If the salt is empty AND there is a ':' in the original hash, we must append ':' at the end
    $testcrypt = md5($plaintext . $salt) . ($salt ? ':' . $salt : (strpos($hashed, ':') !== false ? ':' : ''));
    return Crypt::timingSafeCompare($hashed, $testcrypt);
}