@@ -12,14 +12,14 @@ |
||
| 12 | 12 | |
| 13 | 13 | $salt=self::generateSalt(); |
| 14 | 14 | |
| 15 | - /* Create a string that will be passed to crypt, containing all |
|
| 15 | + /* Create a string that will be passed to crypt, containing all |
|
| 16 | 16 | * of the settings, separated by dollar signs |
| 17 | 17 | */ |
| 18 | - $salt='$'.implode('$',[$bcrypt_version, $cost, $salt]); |
|
| 18 | + $salt='$'.implode('$',[$bcrypt_version, $cost, $salt]); |
|
| 19 | 19 | |
| 20 | - $ciphertext = crypt($plaintext, $salt); |
|
| 20 | + $ciphertext = crypt($plaintext, $salt); |
|
| 21 | 21 | |
| 22 | - return $ciphertext; |
|
| 22 | + return $ciphertext; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public static function verify($plaintext, $ciphertext) |
@@ -24,13 +24,14 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public static function verify($plaintext, $ciphertext) |
| 26 | 26 | { |
| 27 | - if(version_compare(PHP_VERSION, '5.6.0', '>=')){ |
|
| 27 | + if(version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
| 28 | 28 | return hash_equals($ciphertext, crypt($plaintext, $ciphertext)); |
| 29 | 29 | } |
| 30 | 30 | return crypt($plaintext, $ciphertext) == $ciphertext; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public static function generateSalt(){ |
|
| 33 | + public static function generateSalt() |
|
| 34 | + { |
|
| 34 | 35 | /* To generate the salt, first generate enough random bytes. Because |
| 35 | 36 | * base64 returns one character for each 6 bits, the we should generate |
| 36 | 37 | * at least 22*6/8=16.5 bytes, so we generate 17. Then we get the first |
@@ -38,7 +39,7 @@ discard block |
||
| 38 | 39 | */ |
| 39 | 40 | $bytes = openssl_random_pseudo_bytes(17); |
| 40 | 41 | |
| 41 | - if($bytes === false){ |
|
| 42 | + if($bytes === false) { |
|
| 42 | 43 | throw new RuntimeException('Unable to generate a random string'); |
| 43 | 44 | } |
| 44 | 45 | |