line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Authen::PIN;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1069
|
use Digest::MD5 qw(md5);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
103
|
|
4
|
1
|
|
|
1
|
|
1096
|
use Business::CreditCard;
|
|
1
|
|
|
|
|
2341
|
|
|
1
|
|
|
|
|
101
|
|
5
|
1
|
|
|
1
|
|
1191
|
use Number::Encode qw(uniform);
|
|
1
|
|
|
|
|
684
|
|
|
1
|
|
|
|
|
59
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
83
|
|
8
|
1
|
|
|
1
|
|
4
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION);
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
719
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.10';
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new {
|
14
|
0
|
|
|
0
|
0
|
|
my $type = shift;
|
15
|
0
|
|
0
|
|
|
|
my $class = ref($type) || $type || "Authen::PIN";
|
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $template = uc shift;
|
18
|
0
|
|
|
|
|
|
my $start = shift;
|
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
$start = 0 unless $start;
|
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
croak "Template contains unrecognized characters or is invalid"
|
23
|
|
|
|
|
|
|
unless $template =~ /^[0-9PCHV]+$/;
|
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $self = {
|
26
|
|
|
|
|
|
|
template => [ split(//, $template) ],
|
27
|
|
|
|
|
|
|
start => $start,
|
28
|
|
|
|
|
|
|
inc => 1,
|
29
|
|
|
|
|
|
|
count => $start,
|
30
|
|
|
|
|
|
|
p => 0,
|
31
|
|
|
|
|
|
|
c => 0,
|
32
|
|
|
|
|
|
|
h => 0,
|
33
|
|
|
|
|
|
|
v => 0,
|
34
|
|
|
|
|
|
|
};
|
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
for my $d (@{$self->{template}}) {
|
|
0
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if ($d eq 'P') { $self->{p} ++; }
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
elsif ($d eq 'C') {$self->{c} ++; }
|
39
|
0
|
|
|
|
|
|
elsif ($d eq 'H') {$self->{h} ++; }
|
40
|
|
|
|
|
|
|
elsif ($d eq 'V') {$self->{v} ++; }
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
bless $self, $class;
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub set {
|
47
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
48
|
0
|
|
|
|
|
|
my $start = shift;
|
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->{start} = $start;
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub inc {
|
54
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
55
|
0
|
|
|
|
|
|
my $inc = shift;
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->{inc} = $inc;
|
58
|
|
|
|
|
|
|
}
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub pin {
|
61
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $pas = undef;
|
64
|
0
|
|
|
|
|
|
my $ser = undef;
|
65
|
0
|
|
|
|
|
|
my $cnt = undef;
|
66
|
0
|
|
|
|
|
|
my $hsh = undef;
|
67
|
0
|
|
|
|
|
|
my $ret = undef;
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $pas_c = 0;
|
70
|
0
|
|
|
|
|
|
my $cnt_c = 0;
|
71
|
0
|
|
|
|
|
|
my $hsh_c = 0;
|
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if (@_ == 1) {
|
74
|
0
|
|
|
|
|
|
$ser = shift;
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
else {
|
77
|
0
|
|
|
|
|
|
$pas = shift;
|
78
|
0
|
|
|
|
|
|
$ser = join('', @_);
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
0
|
|
|
|
carp("Pass-through not defined in template")
|
82
|
|
|
|
|
|
|
if ($pas and not $self->{p});
|
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if ($self->{c} > 0) {
|
85
|
0
|
|
|
|
|
|
$cnt = $self->{count};
|
86
|
0
|
|
|
|
|
|
$self->{count} += $self->{inc};
|
87
|
|
|
|
|
|
|
}
|
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$hsh = uniform(md5($pas . $ser));
|
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
0
|
|
|
|
if (defined $pas and length($pas) < $self->{p}) {
|
92
|
0
|
|
|
|
|
|
$pas = (0 x ($self->{p} - length($pas))) . $pas;
|
93
|
|
|
|
|
|
|
}
|
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
0
|
|
|
|
if (defined $cnt and length($cnt) < $self->{c}) {
|
96
|
0
|
|
|
|
|
|
$cnt = (0 x ($self->{c} - length($cnt))) . $cnt;
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
0
|
|
|
|
if (defined $hsh and length($hsh) < $self->{h}) {
|
100
|
0
|
|
|
|
|
|
$hsh = (0 x ($self->{h} - length($hsh))) . $hsh;
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
for my $t (@{$self->{template}}) {
|
|
0
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
if ($t =~ /[0-9]/) {
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$ret .= $t;
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
elsif ($t eq 'P') {
|
108
|
0
|
|
|
|
|
|
$ret .= substr($pas, $pas_c ++, 1);
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
elsif ($t eq 'C') {
|
111
|
0
|
|
|
|
|
|
$ret .= substr($cnt, $cnt_c ++, 1);
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
elsif ($t eq 'H') {
|
114
|
0
|
|
|
|
|
|
$ret .= substr($hsh, $hsh_c ++, 1);
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
elsif ($t eq 'V') {
|
117
|
0
|
|
|
|
|
|
$ret .= generate_last_digit($ret);
|
118
|
|
|
|
|
|
|
}
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $ret;
|
122
|
|
|
|
|
|
|
}
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1;
|
126
|
|
|
|
|
|
|
__END__
|