]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/phpass/test.php
Replace phpversion() with PHP_VERSION
[Github/YOURLS.git] / includes / phpass / test.php
1 <?php
2 #
3 # This is a test program for the portable PHP password hashing framework.
4 #
5 # Written by Solar Designer and placed in the public domain.
6 # See PasswordHash.php for more information.
7 #
8
9 require 'PasswordHash.php';
10
11 header('Content-type: text/plain');
12
13 $ok = 0;
14
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);
18
19 $correct = 'test12345';
20 $hash = $t_hasher->HashPassword($correct);
21
22 print 'Hash: ' . $hash . "\n";
23
24 $check = $t_hasher->CheckPassword($correct, $hash);
25 if ($check) $ok++;
26 print "Check correct: '" . $check . "' (should be '1')\n";
27
28 $wrong = 'test12346';
29 $check = $t_hasher->CheckPassword($wrong, $hash);
30 if (!$check) $ok++;
31 print "Check wrong: '" . $check . "' (should be '0' or '')\n";
32
33 unset($t_hasher);
34
35 # Force the use of weaker portable hashes.
36 $t_hasher = new PasswordHash(8, TRUE);
37
38 $hash = $t_hasher->HashPassword($correct);
39
40 print 'Hash: ' . $hash . "\n";
41
42 $check = $t_hasher->CheckPassword($correct, $hash);
43 if ($check) $ok++;
44 print "Check correct: '" . $check . "' (should be '1')\n";
45
46 $check = $t_hasher->CheckPassword($wrong, $hash);
47 if (!$check) $ok++;
48 print "Check wrong: '" . $check . "' (should be '0' or '')\n";
49
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';
56
57 print 'Hash: ' . $hash . "\n";
58
59 $check = $t_hasher->CheckPassword($correct, $hash);
60 if ($check) $ok++;
61 print "Check correct: '" . $check . "' (should be '1')\n";
62
63 $check = $t_hasher->CheckPassword($wrong, $hash);
64 if (!$check) $ok++;
65 print "Check wrong: '" . $check . "' (should be '0' or '')\n";
66
67 if ($ok == 6)
68         print "All tests have PASSED\n";
69 else
70         print "Some tests have FAILED\n";
71
72 ?>