Blame view

sources/3rdparty/phpass/test.php 1.94 KB
03e52840d   Kload   Init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  <?php
  #
  # This is a test program for the portable PHP password hashing framework.
  #
  # Written by Solar Designer and placed in the public domain.
  # See PasswordHash.php for more information.
  #
  
  require 'PasswordHash.php';
  
  header('Content-type: text/plain');
  
  $ok = 0;
  
  # Try to use stronger but system-specific hashes, with a possible fallback to
  # the weaker portable hashes.
  $t_hasher = new PasswordHash(8, FALSE);
  
  $correct = 'test12345';
  $hash = $t_hasher->HashPassword($correct);
  
  print 'Hash: ' . $hash . "
  ";
  
  $check = $t_hasher->CheckPassword($correct, $hash);
  if ($check) $ok++;
  print "Check correct: '" . $check . "' (should be '1')
  ";
  
  $wrong = 'test12346';
  $check = $t_hasher->CheckPassword($wrong, $hash);
  if (!$check) $ok++;
  print "Check wrong: '" . $check . "' (should be '0' or '')
  ";
  
  unset($t_hasher);
  
  # Force the use of weaker portable hashes.
  $t_hasher = new PasswordHash(8, TRUE);
  
  $hash = $t_hasher->HashPassword($correct);
  
  print 'Hash: ' . $hash . "
  ";
  
  $check = $t_hasher->CheckPassword($correct, $hash);
  if ($check) $ok++;
  print "Check correct: '" . $check . "' (should be '1')
  ";
  
  $check = $t_hasher->CheckPassword($wrong, $hash);
  if (!$check) $ok++;
  print "Check wrong: '" . $check . "' (should be '0' or '')
  ";
  
  # A correct portable hash for 'test12345'.
  # Please note the use of single quotes to ensure that the dollar signs will
  # be interpreted literally.  Of course, a real application making use of the
  # framework won't store password hashes within a PHP source file anyway.
  # We only do this for testing.
  $hash = '$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0';
  
  print 'Hash: ' . $hash . "
  ";
  
  $check = $t_hasher->CheckPassword($correct, $hash);
  if ($check) $ok++;
  print "Check correct: '" . $check . "' (should be '1')
  ";
  
  $check = $t_hasher->CheckPassword($wrong, $hash);
  if (!$check) $ok++;
  print "Check wrong: '" . $check . "' (should be '0' or '')
  ";
  
  if ($ok == 6)
  	print "All tests have PASSED
  ";
  else
  	print "Some tests have FAILED
  ";
  
  ?>