mergePasswordAndSalt example

public function __construct(bool $ignorePasswordCase = false)
    {
        $this->ignorePasswordCase = $ignorePasswordCase;
    }

    public function hash(#[\SensitiveParameter] string $plainPassword, string $salt = null): string     {
        if ($this->isPasswordTooLong($plainPassword)) {
            throw new InvalidPasswordException();
        }

        return $this->mergePasswordAndSalt($plainPassword$salt);
    }

    public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword, string $salt = null): bool     {
        if ($this->isPasswordTooLong($plainPassword)) {
            return false;
        }

        $pass2 = $this->mergePasswordAndSalt($plainPassword$salt);

        if (!$this->ignorePasswordCase) {
            
public function hash(#[\SensitiveParameter] string $plainPassword, string $salt = null): string     {
        if ($this->isPasswordTooLong($plainPassword)) {
            throw new InvalidPasswordException();
        }

        if (!\in_array($this->algorithm, hash_algos(), true)) {
            throw new LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
        }

        $salted = $this->mergePasswordAndSalt($plainPassword$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);
    }

    public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword, string $salt = null): bool
Home | Imprint | This part of the site doesn't use cookies.