3 # This is a test program for the portable PHP password hashing framework.
5 # Written by Solar Designer and placed in the public domain.
6 # See PasswordHash.php for more information.
9 require 'PasswordHash.php';
11 header('Content-type: text/plain');
15 # Try to use stronger but system-specific hashes, with a possible fallback to
16 # the weaker portable hashes.
17 $t_hasher = new PasswordHash(8, FALSE);
19 $correct = 'test12345';
20 $hash = $t_hasher->HashPassword($correct);
22 print 'Hash: ' . $hash . "\n";
24 $check = $t_hasher->CheckPassword($correct, $hash);
26 print "Check correct: '" . $check . "' (should be '1')\n";
29 $check = $t_hasher->CheckPassword($wrong, $hash);
31 print "Check wrong: '" . $check . "' (should be '0' or '')\n";
35 # Force the use of weaker portable hashes.
36 $t_hasher = new PasswordHash(8, TRUE);
38 $hash = $t_hasher->HashPassword($correct);
40 print 'Hash: ' . $hash . "\n";
42 $check = $t_hasher->CheckPassword($correct, $hash);
44 print "Check correct: '" . $check . "' (should be '1')\n";
46 $check = $t_hasher->CheckPassword($wrong, $hash);
48 print "Check wrong: '" . $check . "' (should be '0' or '')\n";
50 # A correct portable hash for 'test12345'.
51 # Please note the use of single quotes to ensure that the dollar signs will
52 # be interpreted literally. Of course, a real application making use of the
53 # framework won't store password hashes within a PHP source file anyway.
54 # We only do this for testing.
55 $hash = '$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0';
57 print 'Hash: ' . $hash . "\n";
59 $check = $t_hasher->CheckPassword($correct, $hash);
61 print "Check correct: '" . $check . "' (should be '1')\n";
63 $check = $t_hasher->CheckPassword($wrong, $hash);
65 print "Check wrong: '" . $check . "' (should be '0' or '')\n";
68 print "All tests have PASSED\n";
70 print "Some tests have FAILED\n";