/**
* Hashes a password using the current encryption.
*
* @param string $password The plaintext password to encrypt.
* @param string|integer $algorithm The hashing algorithm to use, represented by `HASH_*` class constants, or a container service ID.
* @param array $options The options for the algorithm to use.
*
* @return string The encrypted password.
*
* @since 3.2.1
* @throws \InvalidArgumentException when the algorithm is not supported
*/
public static function hashPassword($password, $algorithm = self::HASH_BCRYPT, array $options = array())
{
$container = Factory::getContainer();
// If the algorithm is a valid service ID, use that service to generate the hash
if ($container->has($algorithm)) {
return $container->get($algorithm)->hashPassword($password, $options);
}
// Try to load handler
if (isset(self::HASH_ALGORITHMS[$algorithm])) {
return $container->get(self::HASH_ALGORITHMS[$algorithm])->hashPassword($password, $options);
}
// Unsupported algorithm, sorry!
throw new \InvalidArgumentException(sprintf('The %s algorithm is not supported for hashing passwords.', $algorithm));
}