File: basic.t

package info (click to toggle)
libcrypt-passwdmd5-perl 1.3-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 52 kB
  • ctags: 6
  • sloc: perl: 83; makefile: 39
file content (68 lines) | stat: -rw-r--r-- 1,085 bytes parent folder | download | duplicates (4)
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
#
# Basic testing of the hashing function
#

use Crypt::PasswdMD5;

$phrase1 = "hello world\n";
$stage1 = '$1$1234$BhY1eAOOs7IED4HLA5T5o.';

$|=1;

print "1..6\n";

# Hashing of a simple phrase + salt
if (unix_md5_crypt($phrase1, "1234") eq $stage1) {
	print "ok 1\n";
}
else {
	print "not ok 1\n";
}

# Rehash (check) of the phrase
if (unix_md5_crypt($phrase1, $stage1) eq $stage1) {
	print "ok 2\n";
}
else {
	print "not ok 2\n";
}

# Hashing/rehashing of the empty password
$t = unix_md5_crypt('', $$);
if (unix_md5_crypt('', $t) eq $t) {
	print "ok 3\n";
}
else
{	
	print "not ok 3\n";
}

# Make sure null salt works
$t = unix_md5_crypt('test4');
($salt) = ($t =~ m/\$.+\$(.+)\$/);
if (unix_md5_crypt('test4',$salt) eq $t) {
	print "ok 4\n";
}
else
{
	print "not ok 4\n";
}
  
# and again with the Apache Variant
$t = apache_md5_crypt('test5');
($salt) = ($t =~ m/\$.+\$(.+)\$/);
if (apache_md5_crypt('test5',$salt) eq $t) {
        print "ok 5\n";
}
else
{
        print "not ok 5\n";
}
  
if ( $t =~ /^\$apr1\$/ ) {
        print "ok 6\n";
}
else
{
        print "not ok 6\n";
}