Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 10, 2025
1 parent 748b738 commit 6f03e9e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
2 changes: 1 addition & 1 deletion config/hashing.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'bcrypt' => [
'rounds' => env('BCRYPT_ROUNDS', 12),
'verify' => env('HASH_VERIFY', true),
'limit_length' => env('BCRYPT_LIMIT_LENGTH', true),
'limit' => env('BCRYPT_LIMIT', 72),
],

/*
Expand Down
20 changes: 7 additions & 13 deletions src/Illuminate/Hashing/BcryptHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@

use Error;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use InvalidArgumentException;
use RuntimeException;

class BcryptHasher extends AbstractHasher implements HasherContract
{
/**
* The maximum byte length of the value to hash.
*
* @var int
*/
const MAX_BYTE_LENGTH = 72;

/**
* The default cost factor.
*
Expand All @@ -30,11 +24,11 @@ class BcryptHasher extends AbstractHasher implements HasherContract
protected $verifyAlgorithm = false;

/**
* Impose bcrypt byte limit.
* The maximum allowed length of strings that can be hashed.
*
* @var bool
* @var int|null
*/
protected $limitLength = false;
protected $limit;

/**
* Create a new hasher instance.
Expand All @@ -46,7 +40,7 @@ public function __construct(array $options = [])
{
$this->rounds = $options['rounds'] ?? $this->rounds;
$this->verifyAlgorithm = $options['verify'] ?? $this->verifyAlgorithm;
$this->limitLength = $options['limit_length'] ?? $this->limitLength;
$this->limit = $options['limit'] ?? $this->limit;
}

/**
Expand All @@ -61,8 +55,8 @@ public function __construct(array $options = [])
public function make(#[\SensitiveParameter] $value, array $options = [])
{
try {
if ($this->limitLength && strlen($value) > self::MAX_BYTE_LENGTH) {
throw new BcryptValueTooLongException;
if ($this->limit && strlen($value) > $this->limit) {
throw new InvalidArgumentException('Value is too long to hash. Value must be less than '.$this->limit.' bytes.');
}

$hash = password_hash($value, PASSWORD_BCRYPT, [
Expand Down
13 changes: 0 additions & 13 deletions src/Illuminate/Hashing/BcryptValueTooLongException.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Hashing/HasherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function testBasicBcryptHashing()

public function testBcryptValueTooLong()
{
$this->expectException(BcryptValueTooLongException::class);
$hasher = new BcryptHasher(['limit_length' => true]);
$this->expectException(\InvalidArgumentException::class);
$hasher = new BcryptHasher(['limit' => 72]);
$hasher->make(str_repeat('a', 73));
}

Expand Down

0 comments on commit 6f03e9e

Please sign in to comment.