Include Vendor

This commit is contained in:
Mathieu Lagace
2018-06-27 20:31:54 -04:00
parent d0807a7cf5
commit 5fa3c85b97
6624 changed files with 728653 additions and 1 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 $hashedValue
* @param array $options
* @return bool
*/
public function check($value, $hashedValue, array $options = [])
{
if (strlen($hashedValue) === 0) {
return false;
}
return password_verify($value, $hashedValue);
}
}

View File

@@ -0,0 +1,153 @@
<?php
namespace Illuminate\Hashing;
use RuntimeException;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
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;
/**
* 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 = $options['threads'] ?? $this->threads;
}
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*/
public function make($value, array $options = [])
{
$hash = password_hash($value, PASSWORD_ARGON2I, [
'memory_cost' => $this->memory($options),
'time_cost' => $this->time($options),
'threads' => $this->threads($options),
]);
if ($hash === false) {
throw new RuntimeException('Argon2 hashing not supported.');
}
return $hash;
}
/**
* 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, PASSWORD_ARGON2I, [
'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 threads value from the options array.
*
* @param array $options
* @return int
*/
protected function threads(array $options)
{
return $options['threads'] ?? $this->threads;
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace Illuminate\Hashing;
use RuntimeException;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
class BcryptHasher extends AbstractHasher implements HasherContract
{
/**
* The default cost factor.
*
* @var int
*/
protected $rounds = 10;
/**
* Create a new hasher instance.
*
* @param array $options
* @return void
*/
public function __construct(array $options = [])
{
$this->rounds = $options['rounds'] ?? $this->rounds;
}
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*
* @throws \RuntimeException
*/
public function make($value, array $options = [])
{
$hash = password_hash($value, PASSWORD_BCRYPT, [
'cost' => $this->cost($options),
]);
if ($hash === false) {
throw new RuntimeException('Bcrypt hashing not supported.');
}
return $hash;
}
/**
* 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, PASSWORD_BCRYPT, [
'cost' => $this->cost($options),
]);
}
/**
* Set the default password work factor.
*
* @param int $rounds
* @return $this
*/
public function setRounds($rounds)
{
$this->rounds = (int) $rounds;
return $this;
}
/**
* Extract the cost value from the options array.
*
* @param array $options
* @return int
*/
protected function cost(array $options = [])
{
return $options['rounds'] ?? $this->rounds;
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace Illuminate\Hashing;
use Illuminate\Support\Manager;
use 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->app['config']['hashing.bcrypt'] ?? []);
}
/**
* Create an instance of the Argon2 hash Driver.
*
* @return \Illuminate\Hashing\ArgonHasher
*/
public function createArgonDriver()
{
return new ArgonHasher($this->app['config']['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->app['config']['hashing.driver'] ?? 'bcrypt';
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Illuminate\Hashing;
use Illuminate\Support\ServiceProvider;
class HashServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('hash', function ($app) {
return new HashManager($app);
});
$this->app->singleton('hash.driver', function ($app) {
return $app['hash']->driver();
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['hash', 'hash.driver'];
}
}

View File

@@ -0,0 +1,35 @@
{
"name": "illuminate/hashing",
"description": "The Illuminate Hashing package.",
"license": "MIT",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"require": {
"php": "^7.1.3",
"illuminate/contracts": "5.6.*",
"illuminate/support": "5.6.*"
},
"autoload": {
"psr-4": {
"Illuminate\\Hashing\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.6-dev"
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}