App-bcrypt
view release on metacpan or search on metacpan
script/bcrypt view on Meta::CPAN
=head2 Options
=over 4
=item * C<--compare> - the hash to compare to the password
=item * C<--cost>, C<-c> - the cost factor, which should be between 5 and 31, inclusively. This is the exponent for a power of two, so things get slow quickly (default: 12)
=item * C<--debug>, C<-d> - turn on debugging (default: off)
=item * C<--eol>, C<-e> - the string to add to the end of the hash on output (default: newline)
=item * C<--help>, C<-h> - show the documentation and exit. This takes precedence over all other options besides C<--update-modules> and C<--version>.
=item * C<--no-eol>, C<-n> - do not add anything to the end of the line (default: off)
=item * C<--password>, C<-p> - the password to hash or to compare. But, it's probably better to send it through standard input if you are using this as a command-line program and not a library.
=item * C<--quiet>, C<-q> - suppress information messages (default: off)
=item * C<--salt>, C<-s> - the salt to use. This is a string the should encode to 16-octet UTF-8 (default: random string)
=item * C<--type>, C<-t> - the Bcrypt type, which is one of C<2a>, C<2b> (default), C<2x>, or C<2y>
=item * C<--update-modules> - use cpan(1) to update or install all the Perl modules this program needs. This takes precedence over all other options.
script/bcrypt view on Meta::CPAN
Reading password on standard input...
Hello World
Same thing, but without the extra output:
$ perl script/bcrypt -q
Hello World
$2b$12$IqR8.HcodAzvngql3qDw2upnUrjj9HSxutWCgPrUsga0gm7AvTOUu
By default, there's a newline at the end of the hash because it's a normal
output line, but you can remove that with C<--no-eol>. First, normally:
$ bcrypt -q | hexdump -C
Hello World
00000000 24 32 62 24 31 32 24 35 4b 63 68 65 4f 6d 65 48 |$2b$12$5KcheOmeH|
00000010 61 67 52 62 77 2f 4a 57 70 79 54 55 65 73 70 39 |agRbw/JWpyTUesp9|
00000020 67 76 41 58 78 32 66 6e 79 6e 41 33 2f 6b 75 35 |gvAXx2fnynA3/ku5|
00000030 6a 43 50 4a 7a 70 5a 38 39 47 58 65 0a |jCPJzpZ89GXe.|
0000003d
Now, notice the lack of the C<0a> at the end:
$ bcrypt -q --no-eol | hexdump -C
Hello World
00000000 24 32 62 24 31 32 24 4d 36 67 2e 54 64 7a 48 49 |$2b$12$M6g.TdzHI|
00000010 44 58 52 30 73 33 66 2f 66 57 74 74 4f 61 54 70 |DXR0s3f/fWttOaTp|
00000020 34 2f 7a 57 5a 47 63 44 76 56 63 45 6d 6a 49 4e |4/zWZGcDvVcEmjIN|
00000030 50 79 4c 79 41 74 48 62 71 56 79 75 |PyLyAtHbqVyu|
0000003c
Choose your own settings. The value for C<--salt> should be a string that
will UTF-8 encode to exactly 16 octets. Care with C<--cost> because that's
a power of 2:
script/bcrypt view on Meta::CPAN
}
if( $processed_args->{'debug'} ) {
say _dumper($processed_args);
}
state $rc = require Crypt::Bcrypt;
my $hashed = Crypt::Bcrypt::bcrypt( $processed_args->@{qw(password type cost salt)} );
local $\ = do {
if( $processed_args->{'no-eol'} ) { undef }
elsif( $processed_args->{'eol'} ) { $processed_args->{'eol'} }
else { "\n" }
};
print $hashed;
return EX_SUCCESS;
}
sub _defaults () {
my %hash = (
'no-eol' => $ENV{BCRYPT_NO_EOL} // 0,
cost => $ENV{BCRYPT_COST} // 12,
debug => $ENV{BCRYPT_DEBUG} // 0,
eol => $ENV{BCRYPT_EOL} // "\n",
quiet => $ENV{BCRYPT_QUIET} // 0,
salt => _default_salt(),
type => lc( $ENV{BCRYPT_TYPE} // '2b' ),
);
return \%hash;
}
sub _default_salt () {
my $unencoded_salt = do {
script/bcrypt view on Meta::CPAN
}
sub _process_args ($args) {
state $c = require Getopt::Long;
my %opts = _defaults()->%*;
my %opts_description = (
'compare=s' => \ $opts{'compare'},
'cost|c=i' => \ $opts{'cost'},
'debug|d' => \ $opts{'debug'},
'eol|e=s' => \ $opts{'eol'},
'help|h' => \ $opts{'help'},
'no-eol|n' => \ $opts{'no-eol'},
'password|p=s' => \ $opts{'password'},
'quiet|q' => \ $opts{'quiet'},
'salt|s=s' => \ $opts{'salt'},
'type|t=s' => \ $opts{'type'},
'update-modules' => \ $opts{'update-modules'},
'version|v' => \ $opts{'version'},
);
my $ret = Getopt::Long::GetOptionsFromArray( $args, %opts_description );
return unless $ret;
( run in 3.223 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )