File: phpass.t

package info (click to toggle)
libauthen-passphrase-perl 0.008-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 376 kB
  • sloc: perl: 1,932; makefile: 2
file content (106 lines) | stat: -r--r--r-- 2,851 bytes parent folder | download | duplicates (5)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use warnings;
use strict;

use Test::More tests => 100;

BEGIN { use_ok "Authen::Passphrase::PHPass"; }

my $ppr = Authen::Passphrase::PHPass
		->new(nrounds_log2 => 8,
		      salt => "V7qMYJaN",
		      hash => "ABCDEFGHIJKLMNOP");
ok $ppr;
is $ppr->cost, 8;
is $ppr->cost_base64, "6";
is $ppr->nrounds_log2, 8;
is $ppr->nrounds_log2_base64, "6";
is $ppr->salt, "V7qMYJaN";
is $ppr->hash, "ABCDEFGHIJKLMNOP";
is $ppr->hash_base64, "/7oE2JYF5VIG8h2HBtoHE/";

$ppr = Authen::Passphrase::PHPass
		->new(cost => 8,
		      salt => "V7qMYJaN",
		      hash_base64 => "/7oE2JYF5VIG8h2HBtoHE/");
ok $ppr;
is $ppr->cost, 8;
is $ppr->cost_base64, "6";
is $ppr->nrounds_log2, 8;
is $ppr->nrounds_log2_base64, "6";
is $ppr->salt, "V7qMYJaN";
is $ppr->hash, "ABCDEFGHIJKLMNOP";
is $ppr->hash_base64, "/7oE2JYF5VIG8h2HBtoHE/";

$ppr = Authen::Passphrase::PHPass
		->new(cost_base64 => "6",
		      salt => "V7qMYJaN",
		      passphrase => "wibble");
ok $ppr;
is $ppr->cost, 8;
is $ppr->cost_base64, "6";
is $ppr->nrounds_log2, 8;
is $ppr->nrounds_log2_base64, "6";
is $ppr->salt, "V7qMYJaN";
is $ppr->hash_base64, "DLIv8lDL.KgHUVyVKxhSH.";

$ppr = Authen::Passphrase::PHPass
		->new(nrounds_log2_base64 => "6", salt_random => 1,
		      passphrase => "wibble");
ok $ppr;
is $ppr->cost, 8;
is $ppr->cost_base64, "6";
is $ppr->nrounds_log2, 8;
is $ppr->nrounds_log2_base64, "6";
like $ppr->salt, qr#\A[./0-9A-Za-z]{8}\z#;
is length($ppr->hash), 16;
ok $ppr->match("wibble");

$ppr = Authen::Passphrase::PHPass
	->from_crypt('$P$8NaClNaClMeOtoCi6dkB5NlSyY.wFQ.');
ok $ppr;
is $ppr->cost, 10;
is $ppr->salt, "NaClNaCl";
is $ppr->hash_base64, "MeOtoCi6dkB5NlSyY.wFQ.";

$ppr = Authen::Passphrase::PHPass
	->from_rfc2307('{CrYpT}$P$8NaClNaClMeOtoCi6dkB5NlSyY.wFQ.');
ok $ppr;
is $ppr->cost, 10;
is $ppr->salt, "NaClNaCl";
is $ppr->hash_base64, "MeOtoCi6dkB5NlSyY.wFQ.";

my %pprs;
while(<DATA>) {
	chomp;
	s/([^ \n]+) ([^ \n]+) ([^ \n]+) *//;
	my($cost_base64, $salt, $hash_base64) = ($1, $2, $3, $4);
	$ppr = Authen::Passphrase::PHPass
			->new(cost_base64 => $cost_base64,
			      salt => $salt,
			      hash_base64 => $hash_base64);
	ok $ppr;
	is $ppr->cost_base64, $cost_base64;
	is $ppr->salt, $salt;
	is $ppr->hash_base64, $hash_base64;
	eval { $ppr->passphrase }; isnt $@, "";
	my $crypt_string = "\$P\$".$cost_base64.$salt.$hash_base64;
	is $ppr->as_crypt, $crypt_string;
	is $ppr->as_rfc2307, "{CRYPT}$crypt_string";
	$pprs{$_} = $ppr;
}

foreach my $rightphrase (sort keys %pprs) {
	my $ppr = $pprs{$rightphrase};
	foreach my $passphrase (sort keys %pprs) {
		ok ($ppr->match($passphrase) xor $passphrase ne $rightphrase);
	}
}

1;

__DATA__
6 MVeiwNN2 Z9ajy4aaEmIhSGxgfIMbF/
3 tWgAqczl uHKlOhHYT1V80gVQxgypw. 0
7 Fi0425wg bQvE6tzjOfMPGgENlndLm/ 1
8 EP62lbrh mf/uFiTNicupnEEbqAbK70 foo
9 /.ksQxvw hZ7Sdy4MmLyS15OJjhbrG1 supercalifragilisticexpialidocious