| 1 | package Authen::PIN; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Digest::MD5 qw(md5); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Business::CreditCard; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Number::Encode qw(uniform); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '1.10'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 0 | my $type = shift; | |||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $class = ref($type) || $type || "Authen::PIN"; | ||||||||||||||||||||||||||
|
Condition0%0/5
ref $type || $type || 'Authen::PIN'
ref $type or $type
MC/DC0%0/2
ref $type || $type || 'Authen::PIN'
ref $type
$type
Truth table0%0/3
A or B
A= ref $typeB= $type
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | my $template = uc shift; | |||||||||||||||||||||||||||
| 18 | 0 | my $start = shift; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | $start = 0 unless $start; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | croak "Template contains unrecognized characters or is invalid" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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}}) { | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($d eq 'P') { $self->{p} ++; } | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 38 | 0 | elsif ($d eq 'C') {$self->{c} ++; } | |||||||||||||||||||||||||||
| 39 | 0 | elsif ($d eq 'H') {$self->{h} ++; } | |||||||||||||||||||||||||||
| 40 | 0 | elsif ($d eq 'V') {$self->{v} ++; } | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 0 | my $start = shift; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | $self->{start} = $start; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub inc { | ||||||||||||||||||||||||||
|
Subroutine
inc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 0 | my $inc = shift; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | $self->{inc} = $inc; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub pin { | ||||||||||||||||||||||||||
|
Subroutine
pin: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 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 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | $ser = shift; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||
| 77 | 0 | $pas = shift; | |||||||||||||||||||||||||||
| 78 | 0 | $ser = join('', @_); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | carp("Pass-through not defined in template") | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($pas and not $self->{p}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pas and not $self->{"p"}
MC/DC0%0/2
$pas and not $self->{"p"}
$pas
not $self->{"p"}
Truth table0%0/3
A and not(B)
A= $pasB= not $self->{"p"}
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($self->{c} > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | $cnt = $self->{count}; | |||||||||||||||||||||||||||
| 86 | 0 | $self->{count} += $self->{inc}; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $hsh = uniform(md5($pas . $ser)); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (defined $pas and length($pas) < $self->{p}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $pas and length $pas < $self->{"p"}
MC/DC0%0/2
defined $pas and length $pas < $self->{"p"}
defined $pas
length $pas < $self->{"p"}
Truth table0%0/3
A and B
A= defined $pasB= length $pas < $self->{"p"}
| |||||||||||||||||||||||||||||
| 92 | 0 | $pas = (0 x ($self->{p} - length($pas))) . $pas; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if (defined $cnt and length($cnt) < $self->{c}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cnt and length $cnt < $self->{"c"}
MC/DC0%0/2
defined $cnt and length $cnt < $self->{"c"}
defined $cnt
length $cnt < $self->{"c"}
Truth table0%0/3
A and B
A= defined $cntB= length $cnt < $self->{"c"}
| |||||||||||||||||||||||||||||
| 96 | 0 | $cnt = (0 x ($self->{c} - length($cnt))) . $cnt; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if (defined $hsh and length($hsh) < $self->{h}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $hsh and length $hsh < $self->{"h"}
MC/DC0%0/2
defined $hsh and length $hsh < $self->{"h"}
defined $hsh
length $hsh < $self->{"h"}
Truth table0%0/3
A and B
A= defined $hshB= length $hsh < $self->{"h"}
| |||||||||||||||||||||||||||||
| 100 | 0 | $hsh = (0 x ($self->{h} - length($hsh))) . $hsh; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | for my $t (@{$self->{template}}) { | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($t =~ /[0-9]/) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||