- md5
- 560a72821496b44cd22e178a23dc9287
- sha1
- 6e96e32e324b0bc76cffce54fbc0d5dd73631672
- sha256
- 927ffb8151ff381f35714468fffc66ad49fd5ab41c1eb77bb002fc9abb217f45
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Authentication\Password;
\defined('JPATH_PLATFORM') or die;
use Joomla\Authentication\Password\HandlerInterface;
use Joomla\CMS\Crypt\Crypt;
use Joomla\CMS\User\UserHelper;
/**
* Password handler for MD5 hashed passwords
*
* @since 4.0.0
* @deprecated 5.0 Support for MD5 hashed passwords will be removed
*/
class MD5Handler implements HandlerInterface, CheckIfRehashNeededHandlerInterface
{
/**
* Check if the password requires rehashing
*
* @param string $hash The password hash to check
*
* @return boolean
*
* @since 4.0.0
*/
public function checkIfRehashNeeded(string $hash): bool
{
return true;
}
/**
* Generate a hash for a plaintext password
*
* @param string $plaintext The plaintext password to validate
* @param array $options Options for the hashing operation
*
* @return string
*
* @since 4.0.0
*/
public function hashPassword($plaintext, array $options = [])
{
$salt = UserHelper::genRandomPassword(32);
$crypted = md5($plaintext . $salt);
return $crypted . ':' . $salt;
}
/**
* Check that the password handler is supported in this environment
*
* @return boolean
*
* @since 4.0.0
*/
public static function isSupported()
{
return true;
}
/**
* 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);
}
}
The same content is in 51 releases, Joomla 4.0.0-beta6 to 4.2.0-beta2. See them all, or every version of this file.