line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Bcrypt; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
848727
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
62
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
101
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
952
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
11152
|
|
|
2
|
|
|
|
|
14
|
|
9
|
2
|
|
|
2
|
|
3937
|
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); |
|
2
|
|
|
|
|
13536
|
|
|
2
|
|
|
|
|
1018
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
1
|
|
|
1
|
1
|
290
|
my $self = shift; |
13
|
1
|
|
|
|
|
2
|
my $app = shift; |
14
|
1
|
|
50
|
|
|
6
|
my $config = shift || {}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$app->helper( |
17
|
|
|
|
|
|
|
bcrypt => sub { |
18
|
13
|
|
|
13
|
|
191130
|
my $c = shift; |
19
|
13
|
|
|
|
|
35
|
my ( $password, $settings ) = @_; |
20
|
13
|
100
|
66
|
|
|
173
|
unless ( defined $settings && $settings =~ /^\$2a\$/ ) { |
21
|
1
|
|
50
|
|
|
13
|
my $cost = sprintf('%02d', $config->{cost} || 6); |
22
|
1
|
|
|
|
|
6
|
$settings = join( '$', '$2a', $cost, _salt() ); |
23
|
|
|
|
|
|
|
} |
24
|
13
|
|
|
|
|
92
|
return bcrypt( $password, $settings ); |
25
|
|
|
|
|
|
|
} |
26
|
1
|
|
|
|
|
16
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$app->helper( |
29
|
|
|
|
|
|
|
bcrypt_validate => sub { |
30
|
7
|
|
|
7
|
|
176110
|
my $c = shift; |
31
|
7
|
|
|
|
|
19
|
my ( $plain, $crypted ) = @_; |
32
|
7
|
|
|
|
|
84
|
return $c->bcrypt( $plain, $crypted ) eq $crypted; |
33
|
|
|
|
|
|
|
} |
34
|
1
|
|
|
|
|
128
|
); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _salt { |
38
|
1
|
|
|
1
|
|
3
|
my $num = 999999; |
39
|
1
|
|
|
|
|
762
|
my $cr = crypt( rand($num), rand($num) ) . crypt( rand($num), rand($num) ); |
40
|
1
|
|
|
|
|
11
|
en_base64(substr( $cr, 4, 16 )); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |