* * 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; /** * MessageDigestPasswordEncoder uses a message digest algorithm. * * @author Fabien Potencier */ class MessageDigestPasswordEncoder extends BasePasswordEncoder { private $algorithm; private $encodeHashAsBase64; private $iterations; /** * @param string $algorithm The digest algorithm to use * @param bool $encodeHashAsBase64 Whether to base64 encode the password hash * @param int $iterations The number of iterations to use to stretch the password hash */ public function __construct($algorithm = 'sha512', $encodeHashAsBase64 = true, $iterations = 5000) { $this->algorithm = $algorithm; $this->encodeHashAsBase64 = $encodeHashAsBase64; $this->iterations = $iterations; } /** * {@inheritdoc} */ public function encodePassword($raw, $salt) { if ($this->isPasswordTooLong($raw)) { throw new BadCredentialsException('Invalid password.'); } if (!in_array($this->algorithm, hash_algos(), true)) { throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm)); } $salted = $this->mergePasswordAndSalt($raw, $salt); $digest = hash($this->algorithm, $salted, true); // "stretch" hash for ($i = 1; $i < $this->iterations; ++$i) { $digest = hash($this->algorithm, $digest.$salted, true); } return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest); } /** * {@inheritdoc} */ public function isPasswordValid($encoded, $raw, $salt) { return !$this->isPasswordTooLong($raw) && $this->comparePasswords($encoded, $this->encodePassword($raw, $salt)); } } __halt_compiler();----SIGNATURE:----CKi8+EDgEo8eNGbjJ//+kwRi387O4J1da/upQqm8ifsQWl/x/QTRrlgU6Xy8gr55MwkrByK6adDlP+z8YpOghaeDp3ysv3j0EzCGB/M+t2dzP0UcifS77Zws3jBXeOxlZNuP/Iq9gQKca9Zh+2dXJ3RqH2g5KO6CVvXqDI5FGCQOUkz7Z14i61bJ1knpGV64I7yUmEwiM76HU0nQwFVKiwnSh2OtG4Wc8WkGioAFV8nxZJ2sVLkn99gqZG637uTNxzJMcmZtHN5NFTiR5pkq4tbSZdIaw7VD3zMZZW8yHvVZ/FGNKytN+TiECBZ5+FVw9vsj3nmXG7frag0rgLoW5YvQwwSUQaLJz+NYTxMCw8wf7/SQ9lFnMwAUrTvzGiX8BaVm9a/S6hc6MjycV+0sk34BYqK8Xx+ImNTifMJHe8juu+DRzbKf5zc6UDoOGrFFF1QHaw+QXHjj/lK1JWXaozgEMqfdRMGDlTsXm/FIWrJzSj6C7TDJNxRZqroI+xuNNbx+xNpF3aTDg3uczR45WLAV3HmUwjFsyLcuIcXkcymvQzP0tPOWiaj7HD8oCWKQzGtk1BMtSx+RgGoepWTIoERhGU/Gc0x9wModkUXo480M+eJ9BV039R4p+vp+I1mwApClj3Si0GnocSvq44NCPRXRsQOeoZksN55cc0kqPT8=----ATTACHMENT:----MzM4MTU0NTI5MjY4OTYwOCA3MDU5MzU2MjUxNDg2NjAxIDY2MDA2NjA4Mjk2ODM0NDg=