1--TEST--
2Test normal operation of password_needs_rehash()
3--FILE--
4<?php
5//-=-=-=-
6
7// Invalid Hash, always rehash
8var_dump(password_needs_rehash('', PASSWORD_BCRYPT));
9
10// Valid, as it's an unknown algorithm
11var_dump(password_needs_rehash('', 0));
12
13// Valid with cost the same
14var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 10)));
15
16// Valid with cost the same, additional params
17var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 10, 'foo' => 3)));
18
19// Invalid, different (lower) cost
20var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 09)));
21
22// Invalid, different (higher) cost
23var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 11)));
24
25// Valid with cost the default
26$cost = str_pad(PASSWORD_BCRYPT_DEFAULT_COST, 2, '0', STR_PAD_LEFT);
27var_dump(password_needs_rehash('$2y$'.$cost.'$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT));
28
29// Should Issue Needs Rehash, Since Foo is cast to 0...
30var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 'foo')));
31
32
33
34echo "OK!";
35?>
36--EXPECT--
37bool(true)
38bool(false)
39bool(false)
40bool(false)
41bool(true)
42bool(true)
43bool(false)
44bool(true)
45OK!
46