crypto_pwhash_str example

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

        if (\function_exists('sodium_crypto_pwhash_str')) {
            return sodium_crypto_pwhash_str($plainPassword$this->opsLimit, $this->memLimit);
        }

        if (\extension_loaded('libsodium')) {
            return \Sodium\crypto_pwhash_str($plainPassword$this->opsLimit, $this->memLimit);
        }

        throw new LogicException('Libsodium is not available. You should either install the sodium extension or use a different password hasher.');
    }

    public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword): bool     {
        if ('' === $plainPassword) {
            return false;
        }

        
/** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string * @throws SodiumException * @throws TypeError */
    function sodium_crypto_pwhash_str($passwd$opslimit$memlimit)
    {
        return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd$opslimit$memlimit);
    }
}
if (!is_callable('sodium_crypto_pwhash_str_needs_rehash')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash() * @param string $hash * @param int $opslimit * @param int $memlimit * @return bool * * @throws SodiumException */
/** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string * @throws \SodiumException * @throws \TypeError */
    function crypto_pwhash_str($passwd$opslimit$memlimit)
    {
        return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd$opslimit$memlimit);
    }
}
if (!is_callable('\\Sodium\\crypto_pwhash_str_verify')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify() * @param string $passwd * @param string $hash * @return bool * @throws \SodiumException * @throws \TypeError */
    
Home | Imprint | This part of the site doesn't use cookies.