1--TEST-- 2Test hash_pbkdf2() function : error functionality 3--SKIPIF-- 4<?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?> 5--FILE-- 6<?php 7 8/* {{{ proto string hash_pbkdf2(string algo, string password, string salt, int iterations [, int length = 0, bool raw_output = false]) 9Generate a PBKDF2 hash of the given password and salt 10Returns lowercase hexbits by default */ 11 12echo "*** Testing hash_pbkdf2() : error conditions ***\n"; 13 14$password = 'password'; 15$salt = 'salt'; 16 17echo "\n-- Testing hash_pbkdf2() function with less than expected no. of arguments --\n"; 18var_dump(@hash_pbkdf2()); 19echo $php_errormsg . "\n"; 20var_dump(@hash_pbkdf2('crc32')); 21echo $php_errormsg . "\n"; 22var_dump(@hash_pbkdf2('crc32', $password)); 23echo $php_errormsg . "\n"; 24var_dump(@hash_pbkdf2('crc32', $password, $salt)); 25echo $php_errormsg . "\n"; 26 27echo "\n-- Testing hash_pbkdf2() function with more than expected no. of arguments --\n"; 28var_dump(@hash_pbkdf2('crc32', $password, $salt, 10, 10, true, 'extra arg')); 29echo $php_errormsg . "\n"; 30 31echo "\n-- Testing hash_pbkdf2() function with invalid hash algorithm --\n"; 32var_dump(@hash_pbkdf2('foo', $password, $salt, 1)); 33echo $php_errormsg . "\n"; 34 35echo "\n-- Testing hash_pbkdf2() function with invalid iterations --\n"; 36var_dump(@hash_pbkdf2('md5', $password, $salt, 0)); 37echo $php_errormsg . "\n"; 38var_dump(@hash_pbkdf2('md5', $password, $salt, -1)); 39echo $php_errormsg . "\n"; 40 41echo "\n-- Testing hash_pbkdf2() function with invalid length --\n"; 42var_dump(@hash_pbkdf2('md5', $password, $salt, 1, -1)); 43echo $php_errormsg . "\n\n"; 44 45?> 46===Done=== 47--EXPECT-- 48*** Testing hash_pbkdf2() : error conditions *** 49 50-- Testing hash_pbkdf2() function with less than expected no. of arguments -- 51NULL 52hash_pbkdf2() expects at least 4 parameters, 0 given 53NULL 54hash_pbkdf2() expects at least 4 parameters, 1 given 55NULL 56hash_pbkdf2() expects at least 4 parameters, 2 given 57NULL 58hash_pbkdf2() expects at least 4 parameters, 3 given 59 60-- Testing hash_pbkdf2() function with more than expected no. of arguments -- 61NULL 62hash_pbkdf2() expects at most 6 parameters, 7 given 63 64-- Testing hash_pbkdf2() function with invalid hash algorithm -- 65bool(false) 66hash_pbkdf2(): Unknown hashing algorithm: foo 67 68-- Testing hash_pbkdf2() function with invalid iterations -- 69bool(false) 70hash_pbkdf2(): Iterations must be a positive integer: 0 71bool(false) 72hash_pbkdf2(): Iterations must be a positive integer: -1 73 74-- Testing hash_pbkdf2() function with invalid length -- 75bool(false) 76hash_pbkdf2(): Length must be greater than or equal to 0: -1 77 78===Done=== 79