- md5
- 84e7ed64d5c6c694dce145590d72c658
- sha1
- 3b5bb497a275c4cb8f7d026f7229d1f09dba6e7c
- sha256
- 714e991bdfc8eba6362a9169549b0cfabb7ce7d38d96ef2a32f760e42f0b9261
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
<?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;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Password handler supporting testing against a chain of handlers
*
* @since 4.0.0
*/
class ChainedHandler implements HandlerInterface, CheckIfRehashNeededHandlerInterface
{
/**
* The password handlers in use by this chain.
*
* @var HandlerInterface[]
* @since 4.0.0
*/
private $handlers = [];
/**
* Add a handler to the chain
*
* @param HandlerInterface $handler The password handler to add
*
* @return void
*
* @since 4.0.0
*/
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 4.0.0
*/
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 void
*
* @since 4.0.0
* @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 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)
{
foreach ($this->handlers as $handler) {
if ($handler::isSupported() && $handler->validatePassword($plaintext, $hashed)) {
return true;
}
}
return false;
}
}
The same content is in 112 releases, Joomla 5.2.0-beta3 to 6.2.1-rc1. See them all, or every version of this file.