public static function verify(
        HiddenString $password,
        string $stored,
        EncryptionKey $secretKey,
        string $additionalData = ''
    ): bool {
        $config = self::getConfig($stored);
        // Base64-urlsafe encoded, so 4/3 the size of raw binary
        if (Binary::safeStrlen($stored) < ((int) $config->SHORTEST_CIPHERTEXT_LENGTH * 4/3)) {
            throw new InvalidMessage(
                'Encrypted password hash is too short.'
            );
        }
        // First let's decrypt the hash
        $hash_str = Crypto::decryptWithAd($stored, $secretKey, $additionalData, $config->ENCODING);
        // Upon successful decryption, verify the password is correct
        return \sodium_crypto_pwhash_str_verify(
            $hash_str->getString(),
            $password->getString()
        );
    }
public static function verify(
        HiddenString $password,
        string $stored,
        EncryptionKey $secretKey,
        string $additionalData = ''
    ): bool {
        $config = self::getConfig($stored);
        // Base64-urlsafe encoded, so 4/3 the size of raw binary
        if (Binary::safeStrlen($stored) < ((int) $config->SHORTEST_CIPHERTEXT_LENGTH * 4/3)) {
            throw new InvalidMessage(
                'Encrypted password hash is too short.'
            );
        }
        // First let's decrypt the hash
        $hash_str = Crypto::decryptWithAd($stored, $secretKey, $additionalData, $config->ENCODING);
        // Upon successful decryption, verify the password is correct
        return \sodium_crypto_pwhash_str_verify(
            $hash_str->getString(),
            $password->getString()
        );
    }
public static function verify ( HiddenString $ password , string $ stored , EncryptionKey $ secretKey , string $ additionalData = '' ) : bool { $ config = self :: getConfig ( $ stored ) ; // Base64-urlsafe encoded, so 4/3 the size of raw binary if ( Binary :: safeStrlen ( $ stored ) < ( ( int ) $ config -> SHORTEST_CIPHERTEXT_LENGTH * 4 / 3 ) ) { throw new InvalidMessage ( 'Encrypted password hash is too short.' ) ; } // First let's decrypt the hash $ hash_str = Crypto :: decryptWithAd ( $ stored , $ secretKey , $ additionalData , $ config -> ENCODING ) ; // Upon successful decryption, verify the password is correct return \ sodium_crypto_pwhash_str_verify ( $ hash_str -> getString ( ) , $ password -> getString ( ) ) ; }
Decrypt then verify a password

@param HiddenString $password    The user's password
@param string $stored            The encrypted password hash
@param EncryptionKey $secretKey  The master key for all passwords
@param string $additionalData    Additional authenticated data (needed to decrypt)
@return bool                     Is this password valid?

@throws Alerts\InvalidSignature
@throws CannotPerformOperation
@throws InvalidDigestLength
@throws InvalidMessage
@throws InvalidType
@throws \TypeError
Decrypt then verify a password