@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | { |
| 6 | 6 | const VERSION = '1.0.0'; |
| 7 | 7 | |
| 8 | - public static function encrypt($plaintext, $bcrypt_version="2y", $cost=10) |
|
| 8 | + public static function encrypt($plaintext, $bcrypt_version = "2y", $cost = 10) |
|
| 9 | 9 | { |
| 10 | 10 | $salt = self::generate_salt($cost, 17, $bcrypt_version); |
| 11 | 11 | $ciphertext = crypt($plaintext, $salt); |
@@ -15,13 +15,13 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public static function verify($plaintext, $ciphertext) |
| 17 | 17 | { |
| 18 | - if(version_compare(PHP_VERSION, '5.6.0', '>=')){ |
|
| 18 | + if (version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
| 19 | 19 | return hash_equals($ciphertext, crypt($plaintext, $ciphertext)); |
| 20 | 20 | } |
| 21 | 21 | return crypt($plaintext, $ciphertext) == $ciphertext; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public static function generate_salt($cost, $length, $bcrypt_version){ |
|
| 24 | + public static function generate_salt($cost, $length, $bcrypt_version) { |
|
| 25 | 25 | //make sure adding the cost in two digits |
| 26 | 26 | $cost = sprintf('%02d', $cost); |
| 27 | 27 | |
@@ -31,22 +31,22 @@ discard block |
||
| 31 | 31 | * 22 base64 characters |
| 32 | 32 | */ |
| 33 | 33 | $bytes = openssl_random_pseudo_bytes($length); |
| 34 | - if ($bytes === false){ |
|
| 34 | + if ($bytes === false) { |
|
| 35 | 35 | throw new RuntimeException('Unable to generate a random string'); |
| 36 | 36 | } |
| 37 | - $salt=substr(base64_encode($bytes),0,22); |
|
| 37 | + $salt = substr(base64_encode($bytes), 0, 22); |
|
| 38 | 38 | |
| 39 | 39 | /* As blowfish takes a salt with the alphabet ./A-Za-z0-9 we have to |
| 40 | 40 | * replace any '+' in the base64 string with '.'. We don't have to do |
| 41 | 41 | * anything about the '=', as this only occurs when the b64 string is |
| 42 | 42 | * padded, which is always after the first 22 characters. |
| 43 | 43 | */ |
| 44 | - $salt=str_replace("+",".",$salt); |
|
| 44 | + $salt = str_replace("+", ".", $salt); |
|
| 45 | 45 | |
| 46 | 46 | /* Create a string that will be passed to crypt, containing all |
| 47 | 47 | * of the settings, separated by dollar signs |
| 48 | 48 | */ |
| 49 | - $salt='$'.implode('$',[$bcrypt_version, $cost, $salt]); |
|
| 49 | + $salt = '$'.implode('$', [$bcrypt_version, $cost, $salt]); |
|
| 50 | 50 | return $salt; |
| 51 | 51 | } |
| 52 | 52 | } |