/**
* @param string $plainPassword
* @param string $salt
*
* @return string
*
* @throws \InvalidArgumentException
* @throws \LogicException when the algorithm is not supported
*/
private function encodePassword($plainPassword, $salt)
{
Assert::lessThanEq(strlen($plainPassword), self::MAX_PASSWORD_LENGTH, sprintf('The password must be at most %d characters long.', self::MAX_PASSWORD_LENGTH));
if (!in_array($this->algorithm, hash_algos(), true)) {
throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
}
$digest = hash_pbkdf2($this->algorithm, $plainPassword, $salt, $this->iterations, $this->length, true);
return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest);
}