Skip to content

Commit 28f5a91

Browse files
jerguslejkotaylorotwell
authored andcommitted
[5.4] Extract method (#18266)
* Extract method * Update BcryptHasher.php
1 parent 5c85962 commit 28f5a91

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Illuminate/Hashing/BcryptHasher.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class BcryptHasher implements HasherContract
2525
*/
2626
public function make($value, array $options = [])
2727
{
28-
$cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;
29-
30-
$hash = password_hash($value, PASSWORD_BCRYPT, ['cost' => $cost]);
28+
$hash = password_hash($value, PASSWORD_BCRYPT, [
29+
'cost' => $this->cost($options),
30+
]);
3131

3232
if ($hash === false) {
3333
throw new RuntimeException('Bcrypt hashing not supported.');
@@ -63,7 +63,7 @@ public function check($value, $hashedValue, array $options = [])
6363
public function needsRehash($hashedValue, array $options = [])
6464
{
6565
return password_needs_rehash($hashedValue, PASSWORD_BCRYPT, [
66-
'cost' => isset($options['rounds']) ? $options['rounds'] : $this->rounds,
66+
'cost' => $this->cost($options),
6767
]);
6868
}
6969

@@ -79,4 +79,15 @@ public function setRounds($rounds)
7979

8080
return $this;
8181
}
82+
83+
/**
84+
* Extract the cost value from the options array.
85+
*
86+
* @param array $options
87+
* @return int
88+
*/
89+
protected function cost(array $options = [])
90+
{
91+
return isset($options['rounds']) ? $options['rounds'] : $this->rounds;
92+
}
8293
}

0 commit comments

Comments
 (0)