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)); 9var_dump(password_needs_rehash('', 1)); 10var_dump(password_needs_rehash('', '2y')); 11 12// Valid, as it's an unknown algorithm 13var_dump(password_needs_rehash('', PASSWORD_DEFAULT)); 14var_dump(password_needs_rehash('', 0)); 15var_dump(password_needs_rehash('', NULL)); 16 17// Valid with cost the same 18var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 10))); 19 20// Valid with cost the same, additional params 21var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 10, 'foo' => 3))); 22 23// Invalid, different (lower) cost 24var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 0))); 25 26// Invalid, different (higher) cost 27var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 11))); 28 29// Valid with cost the default 30$cost = str_pad(PASSWORD_BCRYPT_DEFAULT_COST, 2, '0', STR_PAD_LEFT); 31var_dump(password_needs_rehash('$2y$'.$cost.'$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT)); 32 33// Should Issue Needs Rehash, Since Foo is cast to 0... 34var_dump(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 'foo'))); 35 36// CRYPT_MD5 37var_dump(password_needs_rehash(crypt('Example', '$1$'), PASSWORD_DEFAULT)); 38 39// CRYPT_SHA512 with 5000 40var_dump(password_needs_rehash(crypt('Example', '$6$rounds=5000$aa$'), PASSWORD_DEFAULT)); 41 42echo "OK!"; 43?> 44--EXPECT-- 45bool(true) 46bool(true) 47bool(true) 48bool(true) 49bool(true) 50bool(true) 51bool(false) 52bool(false) 53bool(true) 54bool(true) 55bool(false) 56bool(true) 57bool(true) 58bool(true) 59OK! 60