diff --git a/src/Illuminate/Hashing/ArgonHasher.php b/src/Illuminate/Hashing/ArgonHasher.php index 759a5e87dba5..233480ea5fb5 100644 --- a/src/Illuminate/Hashing/ArgonHasher.php +++ b/src/Illuminate/Hashing/ArgonHasher.php @@ -2,6 +2,7 @@ namespace Illuminate\Hashing; +use Error; use Illuminate\Contracts\Hashing\Hasher as HasherContract; use RuntimeException; @@ -60,13 +61,13 @@ public function __construct(array $options = []) */ public function make(#[\SensitiveParameter] $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)) { + try { + $hash = password_hash($value, $this->algorithm(), [ + 'memory_cost' => $this->memory($options), + 'time_cost' => $this->time($options), + 'threads' => $this->threads($options), + ]); + } catch (Error) { throw new RuntimeException('Argon2 hashing not supported.'); } diff --git a/src/Illuminate/Hashing/BcryptHasher.php b/src/Illuminate/Hashing/BcryptHasher.php index 0780aee8b419..237d588f7a29 100755 --- a/src/Illuminate/Hashing/BcryptHasher.php +++ b/src/Illuminate/Hashing/BcryptHasher.php @@ -2,6 +2,7 @@ namespace Illuminate\Hashing; +use Error; use Illuminate\Contracts\Hashing\Hasher as HasherContract; use RuntimeException; @@ -44,11 +45,11 @@ public function __construct(array $options = []) */ public function make(#[\SensitiveParameter] $value, array $options = []) { - $hash = password_hash($value, PASSWORD_BCRYPT, [ - 'cost' => $this->cost($options), - ]); - - if ($hash === false) { + try { + $hash = password_hash($value, PASSWORD_BCRYPT, [ + 'cost' => $this->cost($options), + ]); + } catch (Error) { throw new RuntimeException('Bcrypt hashing not supported.'); } diff --git a/tests/Hashing/HasherTest.php b/tests/Hashing/HasherTest.php index 70c6c3d175b0..137f8345b288 100755 --- a/tests/Hashing/HasherTest.php +++ b/tests/Hashing/HasherTest.php @@ -117,4 +117,25 @@ public function testIsHashedWithNonHashedValue() { $this->assertFalse($this->hashManager->isHashed('foo')); } + + public function testBasicBcryptNotSupported() + { + $this->expectException(RuntimeException::class); + + (new BcryptHasher(['rounds' => 0]))->make('password'); + } + + public function testBasicArgon2iNotSupported() + { + $this->expectException(RuntimeException::class); + + (new ArgonHasher(['time' => 0]))->make('password'); + } + + public function testBasicArgon2idNotSupported() + { + $this->expectException(RuntimeException::class); + + (new Argon2IdHasher(['time' => 0]))->make('password'); + } }