| 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
MC/DC0%0/1
$args{"cost"} // 6
$args{"cost"}
Truth table50%1/2
A
A= $args{"cost"}
| |||||||||||||||||||||
| 12 | 1 | ▶ | my $salt = $args{salt} // do { | ||||||||||||||||||
|
Condition33%1/3
$args{"salt"} // do {
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))
}
| |||||||||||||||||||||
| 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
MC/DC0%0/2
$settings // $_set
$settings
$_set
Truth table0%0/3
A // B
A= $settingsB= $_set
| |||||||||||||||||||||
| 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 | ||||||||||||||||||||