line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Command::bcrypt; |
2
|
7
|
|
|
7
|
|
2070321
|
use Mojo::Base 'Mojolicious::Command'; |
|
7
|
|
|
|
|
57
|
|
|
7
|
|
|
|
|
55
|
|
3
|
7
|
|
|
7
|
|
285808
|
use Crypt::Eksblowfish::Bcrypt (); |
|
7
|
|
|
|
|
7569
|
|
|
7
|
|
|
|
|
112
|
|
4
|
7
|
|
|
7
|
|
2842
|
use Crypt::URandom (); |
|
7
|
|
|
|
|
19946
|
|
|
7
|
|
|
|
|
119
|
|
5
|
7
|
|
|
7
|
|
68
|
use Mojo::Util (); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
2522
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has description => 'bcrypt a password using the settings in your Mojolicious app.'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub run { |
14
|
68
|
|
|
68
|
1
|
50192163
|
my ($self, $password, @args) = @_; |
15
|
68
|
100
|
|
|
|
253
|
die $self->usage unless defined $password; |
16
|
|
|
|
|
|
|
|
17
|
66
|
100
|
|
|
|
358
|
Mojo::Util::getopt( |
18
|
|
|
|
|
|
|
\@args, |
19
|
|
|
|
|
|
|
'c|cost=i' => \my $cost, |
20
|
|
|
|
|
|
|
'nkn|no-key-nul' => \my $no_key_nul, |
21
|
|
|
|
|
|
|
's|salt=s' => \my $salt, |
22
|
|
|
|
|
|
|
) or die 'Error parsing options'; |
23
|
57
|
100
|
|
|
|
26007
|
die "unknown args passed: @{[join ', ', map qq{'$_'}, @args]}" if @args; |
|
1
|
|
|
|
|
16
|
|
24
|
|
|
|
|
|
|
|
25
|
56
|
100
|
|
|
|
269
|
if (grep defined, $cost, $no_key_nul, $salt) { |
26
|
50
|
100
|
|
|
|
139
|
if (defined $cost) { |
27
|
22
|
100
|
66
|
|
|
241
|
die 'cost must be between 1 and 99' unless defined $cost and $cost =~ /^\d{1,2}$/ and $cost > 0; |
|
|
|
100
|
|
|
|
|
28
|
|
|
|
|
|
|
} else { |
29
|
28
|
|
|
|
|
65
|
$cost = 12; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
44
|
100
|
|
|
|
139
|
unless ($salt) { |
33
|
18
|
|
|
|
|
90
|
$salt = Crypt::Eksblowfish::Bcrypt::en_base64(Crypt::URandom::urandom(16)); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
44
|
100
|
|
|
|
7040
|
my $nul = $no_key_nul ? '' : 'a'; |
37
|
|
|
|
|
|
|
|
38
|
44
|
|
|
|
|
328
|
say Crypt::Eksblowfish::Bcrypt::bcrypt($password, join '', '$2', $nul, sprintf('$%02i', $cost), '$', $salt); |
39
|
|
|
|
|
|
|
} else { |
40
|
6
|
|
|
|
|
25
|
say $self->app->bcrypt($password); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
__END__ |