summaryrefslogtreecommitdiffstats
path: root/Core/Encoder
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2013-02-05 11:25:15 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2013-02-05 11:25:15 +0100
commit43ddef96e495136b3902c3808ec05818f53b89c4 (patch)
treecfcb7b05678b54931666f4baf64429c011149f1b /Core/Encoder
parenta7eb6e362ce5166d315810ce73700dad5bceaeb1 (diff)
downloadsymfony-security-43ddef96e495136b3902c3808ec05818f53b89c4.zip
symfony-security-43ddef96e495136b3902c3808ec05818f53b89c4.tar.gz
symfony-security-43ddef96e495136b3902c3808ec05818f53b89c4.tar.bz2
fixed CS
Diffstat (limited to 'Core/Encoder')
-rw-r--r--Core/Encoder/BCryptPasswordEncoder.php26
1 files changed, 14 insertions, 12 deletions
diff --git a/Core/Encoder/BCryptPasswordEncoder.php b/Core/Encoder/BCryptPasswordEncoder.php
index acf29fd..cdf204b 100644
--- a/Core/Encoder/BCryptPasswordEncoder.php
+++ b/Core/Encoder/BCryptPasswordEncoder.php
@@ -16,7 +16,7 @@ use Symfony\Component\Security\Core\Util\SecureRandomInterface;
/**
* @author Elnur Abdurrakhimov <elnur@elnur.pro>
- * @author Terje Bråten <terje@braten.be>
+ * @author Terje Bråten <terje@braten.be>
*/
class BCryptPasswordEncoder extends BasePasswordEncoder
{
@@ -33,8 +33,10 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
private static $prefix = null;
/**
- * @param SecureRandomInterface $secureRandom
- * @param int $cost
+ * Constructor.
+ *
+ * @param SecureRandomInterface $secureRandom A SecureRandomInterface instance
+ * @param integer $cost The algorithmic cost that should be used
*
* @throws \InvalidArgumentException if cost is out of range
*/
@@ -44,13 +46,12 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
$cost = (int) $cost;
if ($cost < 4 || $cost > 31) {
- throw new \InvalidArgumentException('Cost must be in the range of 4-31');
+ throw new \InvalidArgumentException('Cost must be in the range of 4-31.');
}
- $this->cost = sprintf("%02d", $cost);
+ $this->cost = sprintf('%02d', $cost);
if (!self::$prefix) {
- self::$prefix = '$'.(version_compare(phpversion(), '5.3.7', '>=')
- ? '2y' : '2a').'$';
+ self::$prefix = '$'.(version_compare(phpversion(), '5.3.7', '>=') ? '2y' : '2a').'$';
}
}
@@ -63,8 +64,7 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
return password_hash($raw, PASSWORD_BCRYPT, array('cost' => $this->cost));
}
- $salt = self::$prefix.$this->cost.'$'.
- $this->encodeSalt($this->getRawSalt());
+ $salt = self::$prefix.$this->cost.'$'.$this->encodeSalt($this->getRawSalt());
$encoded = crypt($raw, $salt);
if (!is_string($encoded) || strlen($encoded) <= 13) {
return false;
@@ -91,7 +91,8 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
}
/**
- * Correctly encode the salt to be used by Bcrypt.
+ * Encodes the salt to be used by Bcrypt.
+ *
* The blowfish/bcrypt algorithm used by PHP crypt expects a different
* set and order of characters than the usual base64_encode function.
* Regular b64: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
@@ -104,6 +105,7 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
* of entropy.
*
* @param bytes $random a string of 16 random bytes
+ *
* @return string Properly encoded salt to use with php crypt function
*
* @throws \InvalidArgumentException if string of random bytes is too short
@@ -112,7 +114,7 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
{
$len = strlen($random);
if ($len < 16) {
- throw new \InvalidArgumentException('The bcrypt salt needs 16 random bytes');
+ throw new \InvalidArgumentException('The bcrypt salt needs 16 random bytes.');
}
if ($len > 16) {
$random = substr($random, 0, 16);
@@ -121,7 +123,7 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
$base64raw = str_replace('+', '.', base64_encode($random));
$salt128bit = substr($base64raw, 0, 21);
$lastchar = substr($base64raw, 21, 1);
- $lastchar = strtr($lastchar, 'AQgw','.Oeu');
+ $lastchar = strtr($lastchar, 'AQgw', '.Oeu');
$salt128bit .= $lastchar;
return $salt128bit;