* * 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:----ktZtISERH10Nh3s7j83e7HtVdJkR6rHmG8Fl1JMlSx0PIH68sPUinCbTn+5FQVRsUh/cetnLTLB/BgJE+yRhuQEmSGXcAD6C/y5FRFFqpZoxyaD9kIL+JmvQb45n4D9vX2OmAmsf4O8uxkTC9a9I3vvl6MBZd/xGWlAt770Rxr05Cpy5Oam71cpl+VQ/Ps+UpKykDyWUAXLaK5Vg/7syER7IOwldGbZxqu/3o19eSN6/QMFpf49EfCBPvfvn04gO1GH1Mp+1a+YCYYnNCLQ1Sz9/m+Oxe0jhcLG/9vxwht1bOqppWd7449v2QukguGiSk9Tt/4Vv/RyTA1CgGLutJftQhc4nHzRCQJ3ntI10Wz5v0Bg69yCbWcWbr1/27/givlKo96UZUdGmKV60kDOJIl+jCyUyzn0d4GkTxHjWWgyU2GaoUGcBd3NLejXjo4L0UdKjNFqkLd4DnJsydOrfvJ6F4xLkN8Ak5Jc7iL9sYv8HQChYWVc7gDl8k8t6CnyzGWKjycfWuI/cRismCS3B9tBP2znNWtPa+bOs1fu1rGIY/8Sd/EpP1UDN7/bdPFgbfiY/rZoK+v48z1RZRTwr9f36FwtD1TKBVUvftR7hZNG6v6EGoRJ+DxDhHpBN0Ub1WZHvi7h1nyQfAzzyxaunZoaNkAr+DYMj9sEs82HHh40=----ATTACHMENT:----MjkwNjQ5NTc4ODI4MTY1IDU0NzcxMDUyNTY3MjA4NDUgNjIxOTk1MDQyNzMyMTA4Nw==