File manager - Edit - /home/ferretapmx/public_html/Authentication.tar
Back
Authentication.php 0000644 00000013641 15231072742 0010244 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Authentication; use Joomla\CMS\Event\User\AuthenticationEvent; use Joomla\CMS\Event\User\AuthorisationEvent; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\PluginHelper; use Joomla\Event\Dispatcher; use Joomla\Event\DispatcherAwareTrait; use Joomla\Event\DispatcherInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Authentication class, provides an interface for the Joomla authentication system * * @since 1.7.0 */ class Authentication { use DispatcherAwareTrait; /** * This is the status code returned when the authentication is success (permit login) * * @var integer * @since 1.7.0 */ public const STATUS_SUCCESS = 1; /** * Status to indicate cancellation of authentication (unused) * * @var integer * @since 1.7.0 */ public const STATUS_CANCEL = 2; /** * This is the status code returned when the authentication failed (prevent login if no success) * * @var integer * @since 1.7.0 */ public const STATUS_FAILURE = 4; /** * This is the status code returned when the account has expired (prevent login) * * @var integer * @since 1.7.0 */ public const STATUS_EXPIRED = 8; /** * This is the status code returned when the account has been denied (prevent login) * * @var integer * @since 1.7.0 */ public const STATUS_DENIED = 16; /** * This is the status code returned when the account doesn't exist (not an error) * * @var integer * @since 1.7.0 */ public const STATUS_UNKNOWN = 32; /** * @var Authentication[] JAuthentication instances container. * @since 1.7.3 */ protected static $instance = []; /** * Plugin Type to run * * @var string * @since 4.0.0 */ protected $pluginType; /** * Constructor * * @param string $pluginType The plugin type to run authorisation and authentication on * @param ?DispatcherInterface $dispatcher The event dispatcher we're going to use * * @since 1.7.0 */ public function __construct(string $pluginType = 'authentication', ?DispatcherInterface $dispatcher = null) { // Set the dispatcher if (!\is_object($dispatcher)) { $dispatcher = Factory::getContainer()->get('dispatcher'); } $this->setDispatcher($dispatcher); $this->pluginType = $pluginType; $isLoaded = PluginHelper::importPlugin($this->pluginType); if (!$isLoaded) { Log::add(Text::_('JLIB_USER_ERROR_AUTHENTICATION_LIBRARIES'), Log::WARNING, 'jerror'); } } /** * Returns the global authentication object, only creating it * if it doesn't already exist. * * @param string $pluginType The plugin type to run authorisation and authentication on * * @return Authentication The global Authentication object * * @since 1.7.0 */ public static function getInstance(string $pluginType = 'authentication') { if (empty(self::$instance[$pluginType])) { self::$instance[$pluginType] = new static($pluginType); } return self::$instance[$pluginType]; } /** * Finds out if a set of login credentials are valid by asking all observing * objects to run their respective authentication routines. * * @param array $credentials Array holding the user credentials. * @param array $options Array holding user options. * * @return AuthenticationResponse Response object with status variable filled in for last plugin or first successful plugin. * * @see AuthenticationResponse * @since 1.7.0 */ public function authenticate($credentials, $options = []) { // Create authentication response $response = new AuthenticationResponse(); // Dispatch onUserAuthenticate event in the isolated dispatcher $dispatcher = new Dispatcher(); PluginHelper::importPlugin($this->pluginType, null, true, $dispatcher); $dispatcher->dispatch('onUserAuthenticate', new AuthenticationEvent('onUserAuthenticate', [ 'credentials' => $credentials, 'options' => $options, 'subject' => $response, ])); if (empty($response->username)) { $response->username = $credentials['username']; } if (empty($response->fullname)) { $response->fullname = $credentials['username']; } if (empty($response->password) && isset($credentials['password'])) { $response->password = $credentials['password']; } return $response; } /** * Authorises that a particular user should be able to login * * @param AuthenticationResponse $response response including username of the user to authorise * @param array $options list of options * * @return AuthenticationResponse[] Array of authentication response objects * * @since 1.7.0 * @throws \Exception */ public function authorise($response, $options = []) { $dispatcher = $this->getDispatcher(); // Get plugins in case they haven't been imported already PluginHelper::importPlugin('user', null, true, $dispatcher); $event = new AuthorisationEvent('onUserAuthorisation', ['subject' => $response, 'options' => $options]); $dispatcher->dispatch('onUserAuthorisation', $event); return $event['result'] ?? []; } } AuthenticationResponse.php 0000644 00000005656 15231072742 0011772 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Authentication; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Authentication response class, provides an object for storing user and error details * * @since 1.7.0 */ class AuthenticationResponse { /** * Response status (see status codes) * * @var string * @since 1.7.0 */ public $status = Authentication::STATUS_FAILURE; /** * The type of authentication that was successful * * @var string * @since 1.7.0 */ public $type = ''; /** * The error message * * @var string * @since 1.7.0 */ public $error_message = ''; /** * Any UTF-8 string that the End User wants to use as a username. * * @var string * @since 1.7.0 */ public $username = ''; /** * Any UTF-8 string that the End User wants to use as a password. * * @var string * @since 1.7.0 */ public $password = ''; /** * The email address of the End User as specified in section 3.4.1 of [RFC2822] * * @var string * @since 1.7.0 */ public $email = ''; /** * UTF-8 string free text representation of the End User's full name. * * @var string * @since 1.7.0 */ public $fullname = ''; /** * The End User's date of birth as YYYY-MM-DD. Any values whose representation uses * fewer than the specified number of digits should be zero-padded. The length of this * value MUST always be 10. If the End User user does not want to reveal any particular * component of this value, it MUST be set to zero. * * For instance, if an End User wants to specify that their date of birth is in 1980, but * not the month or day, the value returned SHALL be "1980-00-00". * * @var string * @since 1.7.0 */ public $birthdate = ''; /** * The End User's gender, "M" for male, "F" for female. * * @var string * @since 1.7.0 */ public $gender = ''; /** * UTF-8 string free text that SHOULD conform to the End User's country's postal system. * * @var string * @since 1.7.0 */ public $postcode = ''; /** * The End User's country of residence as specified by ISO3166. * * @var string * @since 1.7.0 */ public $country = ''; /** * End User's preferred language as specified by ISO639. * * @var string * @since 1.7.0 */ public $language = ''; /** * ASCII string from TimeZone database * * @var string * @since 1.7.0 */ public $timezone = ''; } Password/MD5Handler.php 0000644 00000004715 15231072742 0010754 0 ustar 00 <?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; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Password handler for MD5 hashed passwords * * @since 4.0.0 * * @deprecated 4.0 will be removed in 6.0 * Support for MD5 hashed passwords will be removed without replacement */ 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 : (str_contains($hashed, ':') ? ':' : '')); return Crypt::timingSafeCompare($hashed, $testcrypt); } } Password/Argon2iHandler.php 0000644 00000001651 15231072742 0011664 0 ustar 00 <?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\Argon2iHandler as BaseArgon2iHandler; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Password handler for Argon2i hashed passwords * * @since 4.0.0 */ class Argon2iHandler extends BaseArgon2iHandler implements 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 password_needs_rehash($hash, PASSWORD_ARGON2I); } } Password/ChainedHandler.php 0000644 00000005423 15231072742 0011717 0 ustar 00 <?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; } } Password/CheckIfRehashNeededHandlerInterface.php 0000644 00000001422 15231072742 0015734 0 ustar 00 <?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; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Interface for a password handler which supports checking if the password requires rehashing * * @since 4.0.0 */ interface 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; } Password/Argon2idHandler.php 0000644 00000001657 15231072742 0012036 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2018 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\Argon2idHandler as BaseArgon2idHandler; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Password handler for Argon2id hashed passwords * * @since 4.0.0 */ class Argon2idHandler extends BaseArgon2idHandler implements 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 password_needs_rehash($hash, PASSWORD_ARGON2ID); } } Password/PHPassHandler.php 0000644 00000004417 15231072742 0011524 0 ustar 00 <?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 for PHPass hashed passwords * * @since 4.0.0 * * @deprecated 4.0 will be removed in 6.0 * Support for PHPass hashed passwords will be removed without replacement */ class PHPassHandler 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 = []) { return $this->getPasswordHash()->HashPassword($plaintext); } /** * Check that the password handler is supported in this environment * * @return boolean * * @since 4.0.0 */ public static function isSupported() { return class_exists(\PasswordHash::class); } /** * 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) { return $this->getPasswordHash()->CheckPassword($plaintext, $hashed); } /** * Get an instance of the PasswordHash class * * @return \PasswordHash * * @since 4.0.0 */ private function getPasswordHash(): \PasswordHash { return new \PasswordHash(10, true); } } Password/BCryptHandler.php 0000644 00000001643 15231072742 0011567 0 ustar 00 <?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\BCryptHandler as BaseBCryptHandler; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Password handler for BCrypt hashed passwords * * @since 4.0.0 */ class BCryptHandler extends BaseBCryptHandler implements 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 password_needs_rehash($hash, PASSWORD_BCRYPT); } } Password/.htaccess 0000555 00000000355 15231072742 0010153 0 ustar 00 <FilesMatch '.(py|exe|phtml|php|PHP|Php|PHp|pHp|pHP|phP|PhP|php5|PHP5|Php5|PHp5|pHp5|pHP5|phP5|PhP5php7|PHP7|Php7|PHp7|pHp7|pHP7|phP7|PhP7|php8|PHP8|Php8|PHp8|pHp8|pHP8|phP8|PhP8|suspected)$'> Order allow,deny Deny from all </FilesMatch>