@@ -22,16 +22,16 @@ |
||
22 | 22 | * anything about the '=', as this only occurs when the b64 string is |
23 | 23 | * padded, which is always after the first 22 characters. |
24 | 24 | */ |
25 | - $salt=str_replace("+",".",$salt); |
|
25 | + $salt=str_replace("+",".",$salt); |
|
26 | 26 | |
27 | - /* Create a string that will be passed to crypt, containing all |
|
27 | + /* Create a string that will be passed to crypt, containing all |
|
28 | 28 | * of the settings, separated by dollar signs |
29 | 29 | */ |
30 | - $salt='$'.implode('$',[$bcrypt_version, $cost, $salt]); |
|
30 | + $salt='$'.implode('$',[$bcrypt_version, $cost, $salt]); |
|
31 | 31 | |
32 | - $ciphertext = crypt($plaintext, $salt); |
|
32 | + $ciphertext = crypt($plaintext, $salt); |
|
33 | 33 | |
34 | - return $ciphertext; |
|
34 | + return $ciphertext; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public static function verify($plaintext, $ciphertext) |
@@ -3,40 +3,40 @@ |
||
3 | 3 | |
4 | 4 | class Bcrypt |
5 | 5 | { |
6 | - const VERSION = '1.0.0'; |
|
6 | + const VERSION='1.0.0'; |
|
7 | 7 | |
8 | 8 | public static function encrypt($plaintext, $bcrypt_version="2y", $cost=10) |
9 | 9 | { |
10 | 10 | //make sure adding the cost in two digits |
11 | - $cost = sprintf('%02d', $cost); |
|
11 | + $cost=sprintf('%02d', $cost); |
|
12 | 12 | |
13 | 13 | /* To generate the salt, first generate enough random bytes. Because |
14 | 14 | * base64 returns one character for each 6 bits, the we should generate |
15 | 15 | * at least 22*6/8=16.5 bytes, so we generate 17. Then we get the first |
16 | 16 | * 22 base64 characters |
17 | 17 | */ |
18 | - $salt=substr(base64_encode(openssl_random_pseudo_bytes(17)),0,22); |
|
18 | + $salt=substr(base64_encode(openssl_random_pseudo_bytes(17)), 0, 22); |
|
19 | 19 | |
20 | 20 | /* As blowfish takes a salt with the alphabet ./A-Za-z0-9 we have to |
21 | 21 | * replace any '+' in the base64 string with '.'. We don't have to do |
22 | 22 | * anything about the '=', as this only occurs when the b64 string is |
23 | 23 | * padded, which is always after the first 22 characters. |
24 | 24 | */ |
25 | - $salt=str_replace("+",".",$salt); |
|
25 | + $salt=str_replace("+", ".", $salt); |
|
26 | 26 | |
27 | 27 | /* Create a string that will be passed to crypt, containing all |
28 | 28 | * of the settings, separated by dollar signs |
29 | 29 | */ |
30 | - $salt='$'.implode('$',[$bcrypt_version, $cost, $salt]); |
|
30 | + $salt='$'.implode('$', [$bcrypt_version, $cost, $salt]); |
|
31 | 31 | |
32 | - $ciphertext = crypt($plaintext, $salt); |
|
32 | + $ciphertext=crypt($plaintext, $salt); |
|
33 | 33 | |
34 | 34 | return $ciphertext; |
35 | 35 | } |
36 | 36 | |
37 | 37 | public static function verify($plaintext, $ciphertext) |
38 | 38 | { |
39 | - if(version_compare(PHP_VERSION, '5.6.0', '>=')){ |
|
39 | + if (version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
40 | 40 | return hash_equals($ciphertext, crypt($plaintext, $ciphertext)); |
41 | 41 | } |
42 | 42 | return crypt($plaintext, $ciphertext) == $ciphertext; |