Skip to content

Commit

Permalink
[5.6] Use valid property when assigning threads for ArgonHasher (#22674)
Browse files Browse the repository at this point in the history
* Use valid property when assigning threads

* Use threads instead of processors

* Add array type hinting and update docs
  • Loading branch information
mnabialek authored and taylorotwell committed Jan 7, 2018
1 parent e0272e1 commit 4777740
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/Illuminate/Hashing/ArgonHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ArgonHasher implements HasherContract
*
* @var int
*/
protected $processors = 2;
protected $threads = 2;

/**
* The default memory cost factor.
Expand Down Expand Up @@ -51,7 +51,7 @@ public function make($value, array $options = [])
$hash = password_hash($value, PASSWORD_ARGON2I, [
'memory_cost' => $this->memory($options),
'time_cost' => $this->time($options),
'threads' => $this->processors($options),
'threads' => $this->threads($options),
]);

if ($hash === false) {
Expand Down Expand Up @@ -90,7 +90,7 @@ 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->processors($options),
'threads' => $this->threads($options),
]);
}

Expand All @@ -101,7 +101,7 @@ public function needsRehash($hashedValue, array $options = [])
*
* @return $this;
*/
public function setProcessors(int $threads)
public function setThreads(int $threads)
{
$this->threads = $threads;

Expand Down Expand Up @@ -139,33 +139,33 @@ public function setTime(int $time)
/**
* Extract the memory cost value from the options array.
*
* @param $options
* @param array $options
* @return int
*/
protected function memory($options)
protected function memory(array $options)
{
return $options['memory'] ?? $this->memory;
}

/**
* Extract the time cost value from the options array.
*
* @param $options
* @param array $options
* @return int
*/
protected function time($options)
protected function time(array $options)
{
return $options['time'] ?? $this->time;
}

/**
* Extract the threads value from the options array.
*
* @param $options
* @param array $options
* @return int
*/
protected function processors($options)
protected function threads(array $options)
{
return $options['processors'] ?? $this->processors;
return $options['threads'] ?? $this->threads;
}
}
2 changes: 1 addition & 1 deletion tests/Hashing/HasherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function testBasicArgonHashing()
$this->assertNotSame('password', $value);
$this->assertTrue($hasher->check('password', $value));
$this->assertFalse($hasher->needsRehash($value));
$this->assertTrue($hasher->needsRehash($value, ['processors' => 1]));
$this->assertTrue($hasher->needsRehash($value, ['threads' => 1]));
}
}

0 comments on commit 4777740

Please sign in to comment.