line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Authen::UserVerify; |
2
|
1
|
|
|
1
|
|
28652
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
1153
|
use Data::Random qw/:all/; |
|
1
|
|
|
|
|
3485
|
|
|
1
|
|
|
|
|
195
|
|
5
|
1
|
|
|
1
|
|
1058
|
use Digest::SHA1 qw(sha1 sha1_hex sha1_base64); |
|
1
|
|
|
|
|
1009
|
|
|
1
|
|
|
|
|
76
|
|
6
|
1
|
|
|
1
|
|
1426
|
use Text::CSV_XS; |
|
1
|
|
|
|
|
12204
|
|
|
1
|
|
|
|
|
90
|
|
7
|
1
|
|
|
1
|
|
13
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
844
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.07_5; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
1
|
11901
|
my $class = shift; |
13
|
2
|
|
|
|
|
10
|
my %args = @_; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
5
|
my $self = {}; |
16
|
2
|
|
50
|
|
|
13
|
$self->{file} = $args{file} || "/tmp/reg_users"; |
17
|
2
|
|
|
|
|
19
|
$self->{csv} = Text::CSV_XS->new; |
18
|
2
|
|
|
|
|
244
|
bless $self, $class; |
19
|
2
|
|
|
|
|
8
|
$self->_read(); |
20
|
2
|
|
|
|
|
8
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _read { |
24
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
25
|
2
|
|
|
|
|
453
|
$self->{'user_info'} = {}; |
26
|
2
|
|
|
|
|
7
|
my $file = $self->{'file'}; |
27
|
2
|
50
|
|
|
|
41
|
if ( -f $file ) { # read in data |
28
|
2
|
|
|
|
|
70
|
open(IN, $file); |
29
|
2
|
|
|
|
|
39
|
while (my $line = ) { |
30
|
3
|
|
|
|
|
13
|
$self->{csv}->parse($line); |
31
|
3
|
|
|
|
|
87
|
my ( $hash, @fields ) = $self->{csv}->fields(); |
32
|
3
|
|
|
|
|
78
|
$self->{'user_info'}->{$hash} = [ @fields ]; |
33
|
|
|
|
|
|
|
} |
34
|
2
|
|
|
|
|
22
|
close(IN); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get { |
39
|
3
|
|
|
3
|
1
|
7
|
my ( $self, $id ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
15
|
my $hash = sha1_hex($id); |
42
|
3
|
50
|
|
|
|
12
|
return unless $self->{'user_info'}->{$hash}; |
43
|
3
|
|
|
|
|
4
|
return @{$self->{'user_info'}->{$hash}}; |
|
3
|
|
|
|
|
14
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub add { |
47
|
3
|
|
|
3
|
1
|
1458
|
my ( $self, @fields ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
7
|
return if scalar grep { m/\t/ } @fields; |
|
3
|
|
|
|
|
14
|
|
50
|
|
|
|
|
|
|
|
51
|
3
|
|
|
|
|
4
|
my ( $id, $hash); |
52
|
3
|
|
|
|
|
4
|
do { |
53
|
3
|
|
|
|
|
10
|
$id = join("", rand_chars( set => 'alphanumeric', size => 10)); |
54
|
3
|
|
|
|
|
544
|
$hash = sha1_hex($id); |
55
|
|
|
|
|
|
|
} while ($self->{'user_info'}->{$hash}); |
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
6
|
my $csv = $self->{'csv'}; |
58
|
3
|
|
|
|
|
13
|
my $status = $csv->combine($hash, @fields); |
59
|
3
|
50
|
|
|
|
76
|
unless ($status) { |
60
|
0
|
|
|
|
|
0
|
carp "Could not add data: unable to combine fields\n"; |
61
|
|
|
|
|
|
|
} |
62
|
3
|
|
|
|
|
11
|
my $line = $csv->string(); |
63
|
3
|
|
|
|
|
20
|
my $file = $self->{'file'}; |
64
|
3
|
50
|
|
|
|
113
|
open(OUT, ">>$file") |
65
|
|
|
|
|
|
|
or croak("Unable to open file $file for writing"); |
66
|
3
|
|
|
|
|
20
|
print OUT $line . "\n"; |
67
|
3
|
|
|
|
|
192
|
close(OUT); |
68
|
3
|
|
|
|
|
15
|
$self->{'user_info'}->{$hash} = [ @fields ]; |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
12
|
return $id; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub has { |
74
|
6
|
|
|
6
|
1
|
1061
|
my ( $self, $id ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
6
|
|
|
|
|
29
|
my $hash = sha1_hex($id); |
77
|
6
|
100
|
|
|
|
33
|
return unless $self->{'user_info'}->{$hash}; |
78
|
3
|
|
|
|
|
11
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub delete { |
82
|
3
|
|
|
3
|
1
|
1281
|
my ( $self, $id ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
18
|
my $hash = sha1_hex($id); |
85
|
3
|
|
|
|
|
8
|
my $file = $self->{'file'}; |
86
|
3
|
|
|
|
|
10
|
delete($self->{'user_info'}->{$hash}); |
87
|
3
|
50
|
|
|
|
264
|
open(OUT, ">$file") |
88
|
|
|
|
|
|
|
or croak("Unable to open file $file for writing"); |
89
|
3
|
|
|
|
|
9
|
my $csv = $self->{'csv'}; |
90
|
3
|
|
|
|
|
21
|
while (my ($hash, $data) = each(%{$self->{'user_info'}})) { |
|
6
|
|
|
|
|
26
|
|
91
|
3
|
|
|
|
|
12
|
my $status = $csv->combine($hash, @$data); |
92
|
3
|
50
|
|
|
|
56
|
unless ($status) { |
93
|
0
|
|
|
|
|
0
|
carp "Could not add data: unable to combine fields\n"; |
94
|
|
|
|
|
|
|
} |
95
|
3
|
|
|
|
|
13
|
my $line = $csv->string(); |
96
|
3
|
|
|
|
|
34
|
print OUT $line . "\n"; |
97
|
|
|
|
|
|
|
} |
98
|
3
|
|
|
|
|
110
|
close(OUT); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |