22
33namespace KoenHoeijmakers \LaravelArgon2 ;
44
5- use Illuminate \Contracts \Hashing \Hasher as HasherContract ;
65use RuntimeException ;
6+ use Illuminate \Contracts \Hashing \Hasher as HasherContract ;
77
88class Argon2Hasher implements HasherContract
99{
@@ -13,21 +13,21 @@ class Argon2Hasher implements HasherContract
1313 * @var int
1414 */
1515 protected $ memoryCost = 1024 ;
16-
16+
1717 /**
1818 * Default time cost factor.
1919 *
2020 * @var int
2121 */
2222 protected $ timeCost = 2 ;
23-
23+
2424 /**
2525 * Default threads factor.
2626 *
2727 * @var int
2828 */
2929 protected $ threads = 2 ;
30-
30+
3131 /**
3232 * Hash the given value.
3333 *
@@ -41,20 +41,20 @@ public function make($value, array $options = [])
4141 $ memoryCost = $ options ['memory_cost ' ] ?? $ this ->memoryCost ;
4242 $ timeCost = $ options ['time_cost ' ] ?? $ this ->timeCost ;
4343 $ threads = $ options ['threads ' ] ?? $ this ->threads ;
44-
44+
4545 $ hash = password_hash ($ value , PASSWORD_ARGON2I , [
4646 'memory_cost ' => $ memoryCost ,
4747 'time_cost ' => $ timeCost ,
4848 'threads ' => $ threads ,
4949 ]);
50-
50+
5151 if ($ hash === false ) {
5252 throw new RuntimeException ('Argon2i hashing not supported. ' );
5353 }
54-
54+
5555 return $ hash ;
5656 }
57-
57+
5858 /**
5959 * Check the given plain value against a hash.
6060 *
@@ -68,10 +68,10 @@ public function check($value, $hashedValue, array $options = [])
6868 if (strlen ($ hashedValue ) === 0 ) {
6969 return false ;
7070 }
71-
71+
7272 return password_verify ($ value , $ hashedValue );
7373 }
74-
74+
7575 /**
7676 * Check if the given hash has been hashed using the given options.
7777 *
@@ -84,14 +84,14 @@ public function needsRehash($hashedValue, array $options = [])
8484 $ memoryCost = $ options ['memory_cost ' ] ?? $ this ->memoryCost ;
8585 $ timeCost = $ options ['time_cost ' ] ?? $ this ->timeCost ;
8686 $ threads = $ options ['threads ' ] ?? $ this ->threads ;
87-
87+
8888 return password_needs_rehash ($ hashedValue , PASSWORD_ARGON2I , [
8989 'memory_cost ' => $ memoryCost ,
9090 'time_cost ' => $ timeCost ,
9191 'threads ' => $ threads ,
9292 ]);
9393 }
94-
94+
9595 /**
9696 * Set the default memory cost factor.
9797 *
@@ -101,10 +101,10 @@ public function needsRehash($hashedValue, array $options = [])
101101 public function setMemoryCost ($ memoryCost )
102102 {
103103 $ this ->memoryCost = (int ) $ memoryCost ;
104-
104+
105105 return $ this ;
106106 }
107-
107+
108108 /**
109109 * Set the default time cost factor.
110110 *
@@ -114,10 +114,10 @@ public function setMemoryCost($memoryCost)
114114 public function setTimeCost ($ timeCost )
115115 {
116116 $ this ->timeCost = (int ) $ timeCost ;
117-
117+
118118 return $ this ;
119119 }
120-
120+
121121 /**
122122 * Set the default threads factor.
123123 *
@@ -127,7 +127,7 @@ public function setTimeCost($timeCost)
127127 public function setThreads ($ threads )
128128 {
129129 $ this ->threads = (int ) $ threads ;
130-
130+
131131 return $ this ;
132132 }
133133}
0 commit comments