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());
19var_dump(hash_pbkdf2('md5'));
20var_dump(hash_pbkdf2('md5', $password));
21var_dump(hash_pbkdf2('md5', $password, $salt));
22
23echo "\n-- Testing hash_pbkdf2() function with more than expected no. of arguments --\n";
24var_dump(hash_pbkdf2('md5', $password, $salt, 10, 10, true, 'extra arg'));
25
26echo "\n-- Testing hash_pbkdf2() function with invalid hash algorithm --\n";
27var_dump(hash_pbkdf2('foo', $password, $salt, 1));
28
29echo "\n-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --\n";
30var_dump(hash_pbkdf2('crc32', $password, $salt, 1));
31
32echo "\n-- Testing hash_pbkdf2() function with invalid iterations --\n";
33var_dump(hash_pbkdf2('md5', $password, $salt, 0));
34var_dump(hash_pbkdf2('md5', $password, $salt, -1));
35
36echo "\n-- Testing hash_pbkdf2() function with invalid length --\n";
37var_dump(hash_pbkdf2('md5', $password, $salt, 1, -1));
38
39?>
40===Done===
41--EXPECTF--
42*** Testing hash_pbkdf2() : error conditions ***
43
44-- Testing hash_pbkdf2() function with less than expected no. of arguments --
45
46Warning: hash_pbkdf2() expects at least 4 parameters, 0 given in %s on line %d
47NULL
48
49Warning: hash_pbkdf2() expects at least 4 parameters, 1 given in %s on line %d
50NULL
51
52Warning: hash_pbkdf2() expects at least 4 parameters, 2 given in %s on line %d
53NULL
54
55Warning: hash_pbkdf2() expects at least 4 parameters, 3 given in %s on line %d
56NULL
57
58-- Testing hash_pbkdf2() function with more than expected no. of arguments --
59
60Warning: hash_pbkdf2() expects at most 6 parameters, 7 given in %s on line %d
61NULL
62
63-- Testing hash_pbkdf2() function with invalid hash algorithm --
64
65Warning: hash_pbkdf2(): Unknown hashing algorithm: foo in %s on line %d
66bool(false)
67
68-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --
69
70Warning: hash_pbkdf2(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
71bool(false)
72
73-- Testing hash_pbkdf2() function with invalid iterations --
74
75Warning: hash_pbkdf2(): Iterations must be a positive integer: 0 in %s on line %d
76bool(false)
77
78Warning: hash_pbkdf2(): Iterations must be a positive integer: -1 in %s on line %d
79bool(false)
80
81-- Testing hash_pbkdf2() function with invalid length --
82
83Warning: hash_pbkdf2(): Length must be greater than or equal to 0: -1 in %s on line %d
84bool(false)
85===Done===
86