* * 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:----Tpvcvb+WTXGD4jEte7BMAU+k7AfUn0PL0M56KtT36RwbXWOwzRt0ZeZ4PbiOWCL3w/uOAdIR3DhVaTe/aLImRuXU/Rzgs4zOCn+SlnnOTYCooFQQGTQwQFUm3+T+zoR8kmgi6wPE9Nl4dENSCghjA0MkNPFcj/QCWievpNGiM26BIvhdQL0VnD9usEufywMiwlC9xZMQK95wTQw364f2+fSqr/Kuj1SLBeUdaI6Q5tRo5Xmh61jm+/o008nQAYWdRrCYL8nQzWNMDMRbsOr90MrmmFO86sV5gYWDeS3NkIUxoVrm5L+lp+GAzGW3jPuVu0UBPdacJJZhwrzG6sjnNC8MCvZS0XVgrcIY1bl42oFYSFdHjAHNmSZGzVBnSAqqUeHPFv4caCxQNaBhErMPdNQJOEd3/gTEbKMaNw2OaLbbiPsf5adCAix//yq8BbqHI54n0bU7jfSc3WHbQrhMJAOqdIl6x2D2eCzvutL4TEaCrVRzD1lEyEAufnTxqAvkI7lfVecJ1fLJyENe0huy/W3t6EacmQ4Pldfv8kC5lZIOCUrgCThLMJU/oN40W3lb4sYnzHuur8jihNRdD/1/wq0/s9u6VAcV+/W49PBs+cDSo47YuEg8DsQhxWaOSqVXDvpMdKbXrK5tgB1OGLOy6EnvX1JAUkbPtrxpBRLP+TY=----ATTACHMENT:----OTMzMDQxMTYzOTM4NDg5OSAyMTk1ODQzMTkyODEzNTg3IDY5ODcwNzU4MDYyMTkxNjU=