| @@ -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) | 
| @@ -5,17 +5,17 @@ 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 | //make sure adding the cost in two digits | 
| 11 | 11 |  		$cost = sprintf('%02d', $cost); | 
| 12 | 12 | |
| 13 | - $salt=self::generateSalt(); | |
| 13 | + $salt = self::generateSalt(); | |
| 14 | 14 | |
| 15 | 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 | 20 | $ciphertext = crypt($plaintext, $salt); | 
| 21 | 21 | |
| @@ -24,13 +24,13 @@ 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 | /* To generate the salt, first generate enough random bytes. Because | 
| 35 | 35 | * base64 returns one character for each 6 bits, the we should generate | 
| 36 | 36 | * at least 22*6/8=16.5 bytes, so we generate 17. Then we get the first | 
| @@ -38,18 +38,18 @@ discard block | ||
| 38 | 38 | */ | 
| 39 | 39 | $bytes = openssl_random_pseudo_bytes(17); | 
| 40 | 40 | |
| 41 | -		if($bytes === false){ | |
| 41 | +		if ($bytes === false) { | |
| 42 | 42 |  			throw new RuntimeException('Unable to generate a random string'); | 
| 43 | 43 | } | 
| 44 | 44 | |
| 45 | - $salt = substr(base64_encode($bytes),0,22); | |
| 45 | + $salt = substr(base64_encode($bytes), 0, 22); | |
| 46 | 46 | |
| 47 | 47 | /* As blowfish takes a salt with the alphabet ./A-Za-z0-9 we have to | 
| 48 | 48 | * replace any '+' in the base64 string with '.'. We don't have to do | 
| 49 | 49 | * anything about the '=', as this only occurs when the b64 string is | 
| 50 | 50 | * padded, which is always after the first 22 characters. | 
| 51 | 51 | */ | 
| 52 | -		 $salt=str_replace("+",".",$salt); | |
| 52 | +		 $salt = str_replace("+", ".", $salt); | |
| 53 | 53 | return $salt; | 
| 54 | 54 | } | 
| 55 | 55 | } | 
| @@ -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 | |