* * 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; /** * Argon2iPasswordEncoder uses the Argon2i hashing algorithm. * * @author Zan Baldwin */ class Argon2iPasswordEncoder extends BasePasswordEncoder implements SelfSaltingEncoderInterface { public static function isSupported() { if (\PHP_VERSION_ID >= 70200 && \defined('PASSWORD_ARGON2I')) { return true; } if (\class_exists('ParagonIE_Sodium_Compat') && \method_exists('ParagonIE_Sodium_Compat', 'crypto_pwhash_is_available')) { return \ParagonIE_Sodium_Compat::crypto_pwhash_is_available(); } return \function_exists('sodium_crypto_pwhash_str') || \extension_loaded('libsodium'); } /** * {@inheritdoc} */ public function encodePassword($raw, $salt) { if ($this->isPasswordTooLong($raw)) { throw new BadCredentialsException('Invalid password.'); } if (\PHP_VERSION_ID >= 70200 && \defined('PASSWORD_ARGON2I')) { return $this->encodePasswordNative($raw); } if (\function_exists('sodium_crypto_pwhash_str')) { return $this->encodePasswordSodiumFunction($raw); } if (\extension_loaded('libsodium')) { return $this->encodePasswordSodiumExtension($raw); } throw new \LogicException('Argon2i algorithm is not supported. Please install the libsodium extension or upgrade to PHP 7.2+.'); } /** * {@inheritdoc} */ public function isPasswordValid($encoded, $raw, $salt) { if (\PHP_VERSION_ID >= 70200 && \defined('PASSWORD_ARGON2I')) { return !$this->isPasswordTooLong($raw) && password_verify($raw, $encoded); } if (\function_exists('sodium_crypto_pwhash_str_verify')) { $valid = !$this->isPasswordTooLong($raw) && \sodium_crypto_pwhash_str_verify($encoded, $raw); \sodium_memzero($raw); return $valid; } if (\extension_loaded('libsodium')) { $valid = !$this->isPasswordTooLong($raw) && \Sodium\crypto_pwhash_str_verify($encoded, $raw); \Sodium\memzero($raw); return $valid; } throw new \LogicException('Argon2i algorithm is not supported. Please install the libsodium extension or upgrade to PHP 7.2+.'); } private function encodePasswordNative($raw) { return password_hash($raw, \PASSWORD_ARGON2I); } private function encodePasswordSodiumFunction($raw) { $hash = \sodium_crypto_pwhash_str( $raw, \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE ); \sodium_memzero($raw); return $hash; } private function encodePasswordSodiumExtension($raw) { $hash = \Sodium\crypto_pwhash_str( $raw, \Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, \Sodium\CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE ); \Sodium\memzero($raw); return $hash; } } __halt_compiler();----SIGNATURE:----pmlvYGDka9JG8p+MrFGb6uxlxuT1ap73WHvmXIBKgfL3r+Nctu3v4GencZ3EJETS9WspUnqxI7WADjJ1zMOKypN8FCN66YmyuXUkgNlYfkfIcGqDsUpUmlRmcmaq6MS6RX3OC2bU7CI47aywi+WZ4qBpv7qk86ElAIfv0ccCsIDty9BIaXF0ZtRhBENOrulj8LKzh5wF/yoSpVEJmGHtgZIWC/5XLCUro163rcFukB0aPmLAPel1CDLET32o74QY7XJqdEEwctwcK3X2ZMis0dKJ/5R+uYXKA7i750Xei42L/kS6x25MhInS87DOFYfKDQCQcyPXmAZmlkCrrQY36xaJoXfXZOc5FzOvQljQXV8qHyUBeZ7y4TfNQ4Wxf+rJZnAJ8ZxHkMm1E6dNKgXHUkPfzC3LXen6idvUYlgWjbcP4fIbPEAzp8iVH1Ud7cfaXF4LuGW4WmkU55OKzTYdqCvQav3GsUOfQ8xO/ZRfp7tAQJXNo7OGaAafhK7YGo03Oz++ofeL5kThPAak0Lst8z7tSyrxWw9BHxq8ZM0YyAWuhq4sCAuE4wsdE5ngXF9IvPJvbPsUV4qczNRvgZuoWdckMZm3uOCvfs9F60/MoArmYu4RoCODtJl0SnpLspeFTifoVtvcesjxzkHOiOUw5fDeqz+IyXyyxVizvZUvcTs=----ATTACHMENT:----NTkxMzYxMzI0NDgyNDgyNCA2MDM4NzE0NjYzNTAwNzk5IDQ5OTY4MzIxNjA4Nzg4MTQ=