- md5
- 26bd026957a58a521a4465dd965ecb9b
- sha1
- d42f3a0b4c32b3a27b39f992037954095f571dd5
- sha256
- 8f94e4a8ffbc3c2be28f9fdf0d3039d8b43e33892e0ef57f8dab66aa26a7bb1c
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2018 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 SHA256 hashed passwords
*
* @since 4.0.0
* @deprecated 5.0 Support for SHA256 hashed passwords will be removed
*/
class SHA256Handler 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 = $options['salt'] ?? '';
if ($salt !== '')
{
$salt = preg_replace('|^{sha256}|i', '', $salt);
}
else
{
$salt = UserHelper::genRandomPassword(16);
}
$encrypted = ($salt) ? hash('sha256', $plaintext . $salt) . ':' . $salt : hash('sha256', $plaintext);
return '{SHA256}' . $encrypted;
}
/**
* 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)
{
$parts = explode(':', $hashed);
$salt = @$parts[1];
$testcrypt = $this->hashPassword($plaintext, ['salt' => $salt]);
return Crypt::timingSafeCompare($hashed, $testcrypt);
}
}
The same content is in 3 releases, Joomla 4.0.0-alpha3 to 4.0.0-alpha6. See them all, or every version of this file.