CoreFiles by mySites.guru
MD5Handler.php91 lines, 2,241 bytes, from Joomla_4.0.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 3.10.0-alpha9
md5
a131fe0abf99237333d33a82b191173b
sha1
a3e479c595bb8d354cebc0e4cd5ca3d945417293
sha256
ee0b70c073c6f64eb4b53573e8f3d324dba31edafd4ea91f0a7ccf7e6e822809
<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 * @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       __DEPLOY_VERSION__
 * @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   __DEPLOY_VERSION__
	 */
	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   __DEPLOY_VERSION__
	 */
	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   __DEPLOY_VERSION__
	 */
	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   __DEPLOY_VERSION__
	 */
	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);
	}
}

No other release has this exact content. See every version of this file.