- md5
- 95cfc0f8d13ad24d5aeda13dc5846c78
- sha1
- 96d7d4a11c3045dbe87d91e28eb8d6c12cd0df82
- sha256
- c716fc1d4ab204eee5052ce0ea3c2142f32d8d9167f6b152c7e9ef254f4d17f5
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
<?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;
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 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.