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