* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Core\Encoder; use Symfony\Component\Security\Core\Exception\BadCredentialsException; /** * @author Elnur Abdurrakhimov * @author Terje BrĂ¥ten */ class BCryptPasswordEncoder extends BasePasswordEncoder implements SelfSaltingEncoderInterface { const MAX_PASSWORD_LENGTH = 72; private $cost; /** * @param int $cost The algorithmic cost that should be used * * @throws \RuntimeException When no BCrypt encoder is available * @throws \InvalidArgumentException if cost is out of range */ public function __construct($cost) { $cost = (int) $cost; if ($cost < 4 || $cost > 31) { throw new \InvalidArgumentException('Cost must be in the range of 4-31.'); } $this->cost = $cost; } /** * Encodes the raw password. * * It doesn't work with PHP versions lower than 5.3.7, since * the password compat library uses CRYPT_BLOWFISH hash type with * the "$2y$" salt prefix (which is not available in the early PHP versions). * * @see https://github.com/ircmaxell/password_compat/issues/10#issuecomment-11203833 * * It is almost best to **not** pass a salt and let PHP generate one for you. * * @param string $raw The password to encode * @param string $salt The salt * * @return string The encoded password * * @throws BadCredentialsException when the given password is too long * * @see http://lxr.php.net/xref/PHP_5_5/ext/standard/password.c#111 */ public function encodePassword($raw, $salt) { if ($this->isPasswordTooLong($raw)) { throw new BadCredentialsException('Invalid password.'); } $options = array('cost' => $this->cost); if ($salt) { // Ignore $salt, the auto-generated one is always the best } return password_hash($raw, PASSWORD_BCRYPT, $options); } /** * {@inheritdoc} */ public function isPasswordValid($encoded, $raw, $salt) { return !$this->isPasswordTooLong($raw) && password_verify($raw, $encoded); } } __halt_compiler();----SIGNATURE:----G1v1U5Psqzzd8L+toioZX4qZEUSKTk8W2D4EWAQ+tEagukn16v6C6KJBeEJunrcs/16hVQBFovioSUWR3jmBJIUgs+GBO95dMpEan5Z8cxCVRghd0pDdUMZOkW5kgYBdNtH6v3O6uHQ7M4TqdBDGz9zhoem7ELGub4RDlc+a4VKvYb7gflt5X4ChF8SqB1cy/+ATSPXmDgCrfYOOwBwx1568DRWwUf+iXvlu1wGzGLoCZ3Ivwn0u1RAb1Y45RxJhh8PUPZd5+MgqSPb8dpm7x/5I9vYgWN94g5hWq8JcS8NgL9ifIkMbLOZcNjWfF0phnV83n0AllKdKYq0qvQS0fEEAJpKWEcK3Azy0HbTDroQVoB05EBMvYQ5PwnZvbeAeoY0nZ9r/61hH075RAWFBkxNpipGACVPzcFfwHC34tjdBFpNqLZ0DE+bF2QxiyPaG6BJtvBhnaLTiPNSDJbDMUgRD1QkBkS0G06CO2vYTyMaKxieYC+F6GsF7u5S0w9VuAD/jFJyt+qv3Vg1bULQrUYFfCHQL2WCd2bvHkG2YQgmi7OcfGdxS6YXwaBeX8E8E8lsJ+gjZ8BloYmyQYTJxtmbP1tFQAeSTi27Efz/fPXXjc3zobcdnXXY0oY899yOOR66Gcktexks1eDGaFN8LB98czBLF2k9olSRteievHZc=----ATTACHMENT:----MTE4MDM3MDY0ODEwMDk3NSAyMzQ1Mjk0NTQ1MTI0MTAxIDE1MzI4NjQ1MjgxMDI5NzY=