line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::CryptColumn; |
2
|
|
|
|
|
|
|
$DBIx::Class::CryptColumn::VERSION = '0.008'; |
3
|
1
|
|
|
1
|
|
227442
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Sub::Util 1.40 'set_subname'; |
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
68
|
|
7
|
1
|
|
|
1
|
|
8
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
198
|
use parent 'DBIx::Class'; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
13
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->load_components(qw(InflateColumn::Crypt::Passphrase)); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
1
|
124703
|
my ($self, $attr, @rest) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
4
|
for my $col (grep { !/^-/ } keys %{ $attr }) { |
|
2
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
6
|
|
17
|
1
|
50
|
|
|
|
66
|
next unless my $inflate = $self->column_info($col)->{inflate_passphrase}; |
18
|
1
|
|
|
|
|
131
|
$attr->{$col} = $inflate->hash_password($attr->{$col}); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
176
|
return $self->next::method($attr, @rest); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _export_sub { |
25
|
3
|
|
|
3
|
|
10
|
my ($self, $name, $sub) = @_; |
26
|
3
|
|
|
|
|
87
|
my $full_name = $self->result_class . "::$name"; |
27
|
1
|
|
|
1
|
|
253
|
no strict 'refs'; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
527
|
|
28
|
3
|
|
|
|
|
882
|
*$full_name = set_subname $full_name => $sub; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub register_column { |
32
|
2
|
|
|
2
|
1
|
1935
|
my ($self, $column, $info, @rest) = @_; |
33
|
|
|
|
|
|
|
|
34
|
2
|
100
|
|
|
|
8
|
if (my $args = $info->{inflate_passphrase}) { |
35
|
1
|
50
|
|
|
|
5
|
$self->throw_exception(q['inflate_passphrase' must be a hash reference]) unless ref $args eq 'HASH'; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
2
|
my $crypt_passphrase = Crypt::Passphrase->new(%{$args}); |
|
1
|
|
|
|
|
6
|
|
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
9139
|
if (defined(my $name = $args->{verify_method})) { |
40
|
|
|
|
|
|
|
$self->_export_sub($name, sub { |
41
|
7
|
|
|
7
|
|
8775
|
my ($row, $password) = @_; |
|
|
|
|
7
|
|
|
|
42
|
7
|
|
|
|
|
26
|
return $crypt_passphrase->verify_password($password, $row->get_column($column)); |
43
|
1
|
|
|
|
|
13
|
}); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
1
|
50
|
|
|
|
6
|
if (defined(my $name = $args->{rehash_method})) { |
47
|
|
|
|
|
|
|
$self->_export_sub($name, sub { |
48
|
4
|
|
|
4
|
|
7483
|
my $row = shift; |
|
|
|
|
4
|
|
|
|
49
|
4
|
|
|
|
|
16
|
return $crypt_passphrase->needs_rehash($row->get_column($column)); |
50
|
1
|
|
|
|
|
7
|
}); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
4
|
if (defined(my $name = $args->{verify_and_rehash_method})) { |
54
|
|
|
|
|
|
|
$self->_export_sub($name, sub { |
55
|
1
|
|
|
1
|
|
324
|
my ($row, $password) = @_; |
|
|
|
|
1
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
5
|
my $hash = $row->get_column($column); |
58
|
1
|
|
|
|
|
10
|
my $result = $crypt_passphrase->verify_password($password, $hash); |
59
|
1
|
50
|
33
|
|
|
117
|
if ($result && $crypt_passphrase->needs_rehash($hash)) { |
60
|
1
|
|
|
|
|
22
|
$row->update({ $column => $password })->discard_changes; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
4335
|
return $result; |
64
|
1
|
|
|
|
|
6
|
}); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
3
|
$info->{inflate_passphrase} = $crypt_passphrase; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
10
|
$self->next::method($column, $info, @rest); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub set_column { |
74
|
3
|
|
|
3
|
1
|
523
|
my ($self, $col, $val, @rest) = @_; |
75
|
|
|
|
|
|
|
|
76
|
3
|
|
|
|
|
102
|
my $inflate = $self->column_info($col)->{inflate_passphrase}; |
77
|
3
|
100
|
|
|
|
225
|
$val = $inflate->hash_password($val) if $inflate; |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
171
|
return $self->next::method($col, $val, @rest); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub set_inflated_column { |
83
|
1
|
|
|
1
|
1
|
2290
|
my ($self, $col, $val, @rest) = @_; |
84
|
1
|
|
|
|
|
40
|
local $self->column_info($col)->{inflate_passphrase}; |
85
|
1
|
|
|
|
|
78
|
$self->next::method($col, $val, @rest); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# ABSTRACT: Automatically hash password/passphrase columns |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |