App-bmkpasswd
view release on metacpan or search on metacpan
lib/App/bmkpasswd.pm view on Meta::CPAN
package App::bmkpasswd;
$App::bmkpasswd::VERSION = '2.012002';
use strictures 2;
use Carp;
use Try::Tiny;
use Crypt::Eksblowfish::Bcrypt qw/
bcrypt
en_base64
/;
use parent 'Exporter::Tiny';
our @EXPORT = qw/
mkpasswd
passwdcmp
/;
our @EXPORT_OK = qw/
mkpasswd_available
mkpasswd_forked
/;
{ local @INC = @INC;
pop @INC if $INC[-1] eq '.';
require Bytes::Random::Secure::Tiny;
}
my ($brs, $brsnb);
sub get_brs {
my (%params) = @_;
$params{strong} ?
$brs ||= Bytes::Random::Secure::Tiny->new(Bits => 128, NonBlocking => 0)
: $brsnb ||= Bytes::Random::Secure::Tiny->new(Bits => 128, NonBlocking => 1)
}
sub mkpasswd_forked {
srand; # wrt random-length salts
undef $brs;
undef $brsnb;
}
# can be local'd or replaced, but you get to keep both pieces ->
our $SaltGenerator = sub {
my ($type, $strong) = @_;
my $rnd = get_brs(strong => $strong);
if ($type eq 'bcrypt') {
return en_base64( $rnd->bytes(16) );
}
if ($type eq 'sha') {
my $max = en_base64( $rnd->bytes(16) );
my $initial = substr $max, 0, 8, '';
# Drepper recommends random-length salts:
$initial .= substr $max, 0, 1, '' for 1 .. rand 8;
return $initial
}
if ($type eq 'md5') {
return en_base64( $rnd->bytes(6) );
}
confess "SaltGenerator fell through, unknown type $type"
};
my %_can_haz;
sub have_passwd_xs {
( run in 1.288 second using v1.01-cache-2.11-cpan-63c85eba8c4 )