Created
April 27, 2014 18:08
-
-
Save lifeofguenter/11351790 to your computer and use it in GitHub Desktop.
A simplified "API" tp "safely" hash and verify passwords in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# A simplified "API" to "safely" hash and verify passwords # | |
# # | |
# Author: Günter Grodotzki <[email protected]> # | |
# License: http://www.gnu.org/licenses/gpl-2.0.txt # | |
# Version: 20140425 # | |
################################################################################ | |
use Authen::Passphrase::BlowfishCrypt; | |
sub password_hash { | |
my ($password, $cost) = @_; | |
if (!defined $cost || $cost =~ /\D/ || $cost < 4 || $cost > 31) { | |
$cost = 14; | |
} | |
my $ppr = Authen::Passphrase::BlowfishCrypt->new( | |
cost => $cost, | |
salt_random => 1, | |
passphrase => $password | |
); | |
return $ppr->as_rfc2307; | |
} | |
sub password_verify { | |
my ($password, $hash) = @_; | |
my $ppr = Authen::Passphrase::BlowfishCrypt->from_rfc2307($hash); | |
return $ppr->match($password); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment