CoreFiles by mySites.guru
ChainedHandler.php116 lines, 2,560 bytes, from Joomla_4.0.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 3.10.0-alpha9
md5
755a92555efd877dbfe73d01508c9ede
sha1
3c5bd61e4a7d8a4260ab7f5aa98675cc37366f46
sha256
647762b04f2286a6f98ed2368d2b16a28fee316ba55e94492ced9ffeb0863052
<?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;

/**
 * Password handler supporting testing against a chain of handlers
 *
 * @since  __DEPLOY_VERSION__
 */
class ChainedHandler implements HandlerInterface, CheckIfRehashNeededHandlerInterface
{
	/**
	 * The password handlers in use by this chain.
	 *
	 * @var    HandlerInterface[]
	 * @since  __DEPLOY_VERSION__
	 */
	private $handlers = [];

	/**
	 * Add a handler to the chain
	 *
	 * @param   HandlerInterface  $handler  The password handler to add
	 *
	 * @return  void
	 *
	 * @since   __DEPLOY_VERSION__
	 */
	public function addHandler(HandlerInterface $handler)
	{
		$this->handlers[] = $handler;
	}

	/**
	 * 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
	{
		foreach ($this->handlers as $handler)
		{
			if ($handler instanceof CheckIfRehashNeededHandlerInterface && $handler->isSupported() && $handler->checkIfRehashNeeded($hash))
			{
				return true;
			}
		}

		return false;
	}

	/**
	 * 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__
	 * @throws  \RuntimeException
	 */
	public function hashPassword($plaintext, array $options = [])
	{
		throw new \RuntimeException('The chained password handler cannot be used to hash a password');
	}

	/**
	 * 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)
	{
		foreach ($this->handlers as $handler)
		{
			if ($handler->isSupported() && $handler->validatePassword($plaintext, $hashed))
			{
				return true;
			}
		}

		return false;
	}
}

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