Crypt::Bcrypt::Easy - Simple interface to bcrypted passwords
use Crypt::Bcrypt::Easy; # Generate bcrypted passwords: my $plain = 'my_password'; my $passwd = bcrypt->crypt( $plain ); # Generate passwords with non-default options: my $passwd = bcrypt->crypt( text => $plain, cost => 10 ); # Compare passwords: if (bcrypt->compare( text => $plain, crypt => $passwd )) { # Successful match } # Spawn a new instance that will generate passwords using a different # default workcost: my $bc = bcrypt( cost => 10 ); my $passwd = $bc->crypt( $plain ); # Without imported constructor: use Crypt::Bcrypt::Easy (); my $passwd = Crypt::Bcrypt::Easy->crypt( text => $plain, cost => 10 )
This module provides an easy interface to creating and comparing bcrypt-hashed passwords via App::bmkpasswd's exported helpers (which were created to power bmkpasswd(1) and are a bit awkward to use directly).
bmkpasswd(1)
This POD briefly covers usage of this interface; see App::bmkpasswd for more details on bcrypt, internals, and documentation regarding the more flexible functional interface.
This module uses Exporter::Tiny; you can rename the "bcrypt" function as-needed:
use Crypt::Bcrypt::Easy 'bcrypt' => { -as => 'bc' };
my $bcrypt = bcrypt( cost => 10 );
Creates and returns a new Crypt::Bcrypt::Easy object.
The default cost is '08'. This can be also be tuned for individual runs; see "crypt".
cost
(This is merely a convenience function for calling Crypt::Bcrypt::Easy->new.)
Crypt::Bcrypt::Easy->new
If your application generates passwords in multiple child processes or threads, you can cause "mkpasswd_forked" in App::bmkpasswd to be automatically called during object construction in each individual process by specifying the reset_seed option:
reset_seed
my $bcrypt = bcrypt( reset_seed => 1, cost => 8 );
(The reset_seed option was added in v2.7.1.)
v2.7.1
Create and return a new password hash:
my $crypted = bcrypt->crypt( 'my_password' );
Override default options (see App::bmkpasswd):
my $crypted = bcrypt->crypt( text => 'my_password', cost => 10, strong => 1, );
Specifying a boolean true 'strong =>' parameter enables strongly-random salts (see App::bmkpasswd).
if (bcrypt->compare(text => 'my_password', crypt => $crypted)) { ... }
Returns boolean true if hashes match. Accepts any type of hash supported by App::bmkpasswd and your system; see "passwdcmp" in App::bmkpasswd.
Returns the current work-cost value; see App::bmkpasswd.
Jon Portnoy <avenj@cobaltirc.org>
To install App::bmkpasswd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::bmkpasswd
CPAN shell
perl -MCPAN -e shell install App::bmkpasswd
For more information on module installation, please visit the detailed CPAN module installation guide.