Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace Illuminate\Hashing;
abstract class AbstractHasher
{
/**
* Get information about the given hashed value.
*
* @param string $hashedValue
* @return array
*/
public function info($hashedValue)
{
return password_get_info($hashedValue);
}
/**
* Check the given plain value against a hash.
*
* @param string $value
* @param string|null $hashedValue
* @param array $options
* @return bool
*/
public function check($value, $hashedValue, array $options = [])
{
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
return false;
}
return password_verify($value, $hashedValue);
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Illuminate\Hashing;
use RuntimeException;
class Argon2IdHasher extends ArgonHasher
{
/**
* Check the given plain value against a hash.
*
* @param string $value
* @param string|null $hashedValue
* @param array $options
* @return bool
*
* @throws \RuntimeException
*/
public function check($value, $hashedValue, array $options = [])
{
if ($this->verifyAlgorithm && $this->info($hashedValue)['algoName'] !== 'argon2id') {
throw new RuntimeException('This password does not use the Argon2id algorithm.');
}
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
return false;
}
return password_verify($value, $hashedValue);
}
/**
* Get the algorithm that should be used for hashing.
*
* @return int
*/
protected function algorithm()
{
return PASSWORD_ARGON2ID;
}
}

View File

@@ -0,0 +1,196 @@
<?php
namespace Illuminate\Hashing;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use RuntimeException;
class ArgonHasher extends AbstractHasher implements HasherContract
{
/**
* The default memory cost factor.
*
* @var int
*/
protected $memory = 1024;
/**
* The default time cost factor.
*
* @var int
*/
protected $time = 2;
/**
* The default threads factor.
*
* @var int
*/
protected $threads = 2;
/**
* Indicates whether to perform an algorithm check.
*
* @var bool
*/
protected $verifyAlgorithm = false;
/**
* Create a new hasher instance.
*
* @param array $options
* @return void
*/
public function __construct(array $options = [])
{
$this->time = $options['time'] ?? $this->time;
$this->memory = $options['memory'] ?? $this->memory;
$this->threads = $this->threads($options);
$this->verifyAlgorithm = $options['verify'] ?? $this->verifyAlgorithm;
}
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*
* @throws \RuntimeException
*/
public function make($value, array $options = [])
{
$hash = @password_hash($value, $this->algorithm(), [
'memory_cost' => $this->memory($options),
'time_cost' => $this->time($options),
'threads' => $this->threads($options),
]);
if (! is_string($hash)) {
throw new RuntimeException('Argon2 hashing not supported.');
}
return $hash;
}
/**
* Get the algorithm that should be used for hashing.
*
* @return int
*/
protected function algorithm()
{
return PASSWORD_ARGON2I;
}
/**
* Check the given plain value against a hash.
*
* @param string $value
* @param string $hashedValue
* @param array $options
* @return bool
*
* @throws \RuntimeException
*/
public function check($value, $hashedValue, array $options = [])
{
if ($this->verifyAlgorithm && $this->info($hashedValue)['algoName'] !== 'argon2i') {
throw new RuntimeException('This password does not use the Argon2i algorithm.');
}
return parent::check($value, $hashedValue, $options);
}
/**
* Check if the given hash has been hashed using the given options.
*
* @param string $hashedValue
* @param array $options
* @return bool
*/
public function needsRehash($hashedValue, array $options = [])
{
return password_needs_rehash($hashedValue, $this->algorithm(), [
'memory_cost' => $this->memory($options),
'time_cost' => $this->time($options),
'threads' => $this->threads($options),
]);
}
/**
* Set the default password memory factor.
*
* @param int $memory
* @return $this
*/
public function setMemory(int $memory)
{
$this->memory = $memory;
return $this;
}
/**
* Set the default password timing factor.
*
* @param int $time
* @return $this
*/
public function setTime(int $time)
{
$this->time = $time;
return $this;
}
/**
* Set the default password threads factor.
*
* @param int $threads
* @return $this
*/
public function setThreads(int $threads)
{
$this->threads = $threads;
return $this;
}
/**
* Extract the memory cost value from the options array.
*
* @param array $options
* @return int
*/
protected function memory(array $options)
{
return $options['memory'] ?? $this->memory;
}
/**
* Extract the time cost value from the options array.
*
* @param array $options
* @return int
*/
protected function time(array $options)
{
return $options['time'] ?? $this->time;
}
/**
* Extract the thread's value from the options array.
*
* @param array $options
* @return int
*/
protected function threads(array $options)
{
if (defined('PASSWORD_ARGON2_PROVIDER') && PASSWORD_ARGON2_PROVIDER === 'sodium') {
return 1;
}
return $options['threads'] ?? $this->threads;
}
}

View File

@@ -2,23 +2,42 @@
namespace Illuminate\Hashing;
use RuntimeException;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use RuntimeException;
class BcryptHasher implements HasherContract
class BcryptHasher extends AbstractHasher implements HasherContract
{
/**
* Default crypt cost factor.
* The default cost factor.
*
* @var int
*/
protected $rounds = 10;
/**
* Indicates whether to perform an algorithm check.
*
* @var bool
*/
protected $verifyAlgorithm = false;
/**
* Create a new hasher instance.
*
* @param array $options
* @return void
*/
public function __construct(array $options = [])
{
$this->rounds = $options['rounds'] ?? $this->rounds;
$this->verifyAlgorithm = $options['verify'] ?? $this->verifyAlgorithm;
}
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @param array $options
* @return string
*
* @throws \RuntimeException
@@ -41,23 +60,25 @@ class BcryptHasher implements HasherContract
*
* @param string $value
* @param string $hashedValue
* @param array $options
* @param array $options
* @return bool
*
* @throws \RuntimeException
*/
public function check($value, $hashedValue, array $options = [])
{
if (strlen($hashedValue) === 0) {
return false;
if ($this->verifyAlgorithm && $this->info($hashedValue)['algoName'] !== 'bcrypt') {
throw new RuntimeException('This password does not use the Bcrypt algorithm.');
}
return password_verify($value, $hashedValue);
return parent::check($value, $hashedValue, $options);
}
/**
* Check if the given hash has been hashed using the given options.
*
* @param string $hashedValue
* @param array $options
* @param array $options
* @return bool
*/
public function needsRehash($hashedValue, array $options = [])
@@ -88,6 +109,6 @@ class BcryptHasher implements HasherContract
*/
protected function cost(array $options = [])
{
return isset($options['rounds']) ? $options['rounds'] : $this->rounds;
return $options['rounds'] ?? $this->rounds;
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace Illuminate\Hashing;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Support\Manager;
/**
* @mixin \Illuminate\Contracts\Hashing\Hasher
*/
class HashManager extends Manager implements Hasher
{
/**
* Create an instance of the Bcrypt hash Driver.
*
* @return \Illuminate\Hashing\BcryptHasher
*/
public function createBcryptDriver()
{
return new BcryptHasher($this->config->get('hashing.bcrypt') ?? []);
}
/**
* Create an instance of the Argon2i hash Driver.
*
* @return \Illuminate\Hashing\ArgonHasher
*/
public function createArgonDriver()
{
return new ArgonHasher($this->config->get('hashing.argon') ?? []);
}
/**
* Create an instance of the Argon2id hash Driver.
*
* @return \Illuminate\Hashing\Argon2IdHasher
*/
public function createArgon2idDriver()
{
return new Argon2IdHasher($this->config->get('hashing.argon') ?? []);
}
/**
* Get information about the given hashed value.
*
* @param string $hashedValue
* @return array
*/
public function info($hashedValue)
{
return $this->driver()->info($hashedValue);
}
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*/
public function make($value, array $options = [])
{
return $this->driver()->make($value, $options);
}
/**
* Check the given plain value against a hash.
*
* @param string $value
* @param string $hashedValue
* @param array $options
* @return bool
*/
public function check($value, $hashedValue, array $options = [])
{
return $this->driver()->check($value, $hashedValue, $options);
}
/**
* Check if the given hash has been hashed using the given options.
*
* @param string $hashedValue
* @param array $options
* @return bool
*/
public function needsRehash($hashedValue, array $options = [])
{
return $this->driver()->needsRehash($hashedValue, $options);
}
/**
* Get the default driver name.
*
* @return string
*/
public function getDefaultDriver()
{
return $this->config->get('hashing.driver', 'bcrypt');
}
}

View File

@@ -2,17 +2,11 @@
namespace Illuminate\Hashing;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
class HashServiceProvider extends ServiceProvider
class HashServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
@@ -20,8 +14,12 @@ class HashServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->singleton('hash', function () {
return new BcryptHasher;
$this->app->singleton('hash', function ($app) {
return new HashManager($app);
});
$this->app->singleton('hash.driver', function ($app) {
return $app['hash']->driver();
});
}
@@ -32,6 +30,6 @@ class HashServiceProvider extends ServiceProvider
*/
public function provides()
{
return ['hash'];
return ['hash', 'hash.driver'];
}
}

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Taylor Otwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -14,9 +14,9 @@
}
],
"require": {
"php": ">=5.6.4",
"illuminate/contracts": "5.4.*",
"illuminate/support": "5.4.*"
"php": "^8.0.2",
"illuminate/contracts": "^9.0",
"illuminate/support": "^9.0"
},
"autoload": {
"psr-4": {
@@ -25,7 +25,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
"dev-master": "9.x-dev"
}
},
"config": {