blib/lib/Kelp/Module/Bcrypt.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 61.1% 22 / 36 CC 4 SCAR 12.9
CC
4
Cov
69%
__ANON__
6.0
build
3.8
BEGIN
1.0
CRAP 3.6
↑ Summary
1 package Kelp::Module::Bcrypt;
2  
3 1 ▶use Kelp::Base 'Kelp::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = 0.1;
7  
8 sub build {
9 1 ▶ my ( $self, %args ) = @_;
Subroutine build: called CC=3 SCAR=13.3
Pod documented
10  
11 1 ▶ my $cost = sprintf( '%02d', $args{cost} // 6 );
Condition50%1/2
$args{"cost"} // 6
l!l
01
MC/DC0%0/1
$args{"cost"} // 6
$args{"cost"}
Truth table50%1/2
A
A= $args{"cost"}
Aresult
11
00
12 1 ▶ my $salt = $args{salt} // do {
Condition33%1/3
$args{"salt"} // do {
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"salt"} // do { my $num = 999999; my $rnd = crypt(rand $num, rand $num) . crypt(rand $num, rand $num); &en_base64(substr($rnd, 4, 16)) }
$args{"salt"} do { my $num = 999999; my $rnd = crypt(rand $num, rand $num) . crypt(rand $num, rand $num); &en_base64(substr($rnd, 4, 16)) }
Truth table33%1/3
A // B
A= $args{"salt"}B= do { my $num = 999999; my $rnd = crypt(rand $num, rand $num) . crypt(rand $num, rand $num); &en_base64(substr($rnd, 4, 16)) }
ABresult
1X1
011
000
13 1 my $num = 999999;
14 1 my $rnd = crypt( rand($num), rand($num) ) . crypt( rand($num), rand($num) );
15 1 en_base64( substr( $rnd, 4, 16 ) );
16 };
17 1 my $_set = join( '$', '$2a', $cost, $salt );
18  
19 $self->register(
20 bcrypt => sub {
21 0 ▶ my ( $app, $text, $settings ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
22 0 ▶ return bcrypt( $text, $settings // $_set );
Condition0%0/3
$settings // $_set
l!l&&r!l&&!r
000
MC/DC0%0/2
$settings // $_set
$settings $_set
Truth table0%0/3
A // B
A= $settingsB= $_set
ABresult
1X1
011
000
23 }
24 1 );
25 }
26  
27 1 1;
28  
29 __END__
30  
31 =pod
32  
33 =head1 TITLE
34  
35 Kelp::Module::Bcrypt - Bcrypt your passwords
36  
37 =head1 SYNOPSIS
38  
39 # conf/config.pl
40 {
41 modules_init => {
42 Bcrypt => {
43 cost => 6,
44 salt => 'secret salt passphrase'
45 }
46 };
47 };
48  
49 # lib/MyApp.pm
50 ...
51  
52 sub some_soute {
53 my $self = shift;
54 my $crypted_password = $self->bcrypt($plain_password);
55 }
56  
57 sub another_route { # Maybe a bridge?
58 my $self = shift;
59 if ( $self->bcrypt($plain_password) eq $crypted_passwrod ) {
60 ...;
61 }
62 }
63  
64 =head1 TITLE
65  
66 This module adds bcrypt to your Kelp app
67  
68 =head1 REGISTERED METHODS
69  
70 =head2 bcrypt( $text, $settings )
71  
72 Returns the bcrypted C<$text>. If the settings are not provided, it will
73 use the options in the configuration.
74  
75 =head1 AUTHOR
76  
77 Stefan G - mimimal E<lt>atE<lt> cpan.org
78  
79  
80 =head1 SEE ALSO
81  
82 L<Kelp>, L<Crypt::Eksblowfish::Bcrypt>
83  
84 =head1 LICENSE
85  
86 Perl
87  
88 =cut
↑ Summary