add password hashing
This commit is contained in:
parent
8057c16cc4
commit
058d93a6fd
1 changed files with 18 additions and 0 deletions
18
index.pl
18
index.pl
|
@ -3,6 +3,7 @@
|
||||||
use Mojolicious::Lite;
|
use Mojolicious::Lite;
|
||||||
use Mojolicious::Plugin::Authentication;
|
use Mojolicious::Plugin::Authentication;
|
||||||
use Cache::File;
|
use Cache::File;
|
||||||
|
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DBI;
|
use DBI;
|
||||||
use Encode qw(decode encode);
|
use Encode qw(decode encode);
|
||||||
|
@ -225,6 +226,23 @@ app->attr(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sub hash_password {
|
||||||
|
my ($password) = @_;
|
||||||
|
my @salt_bytes = map { int( rand(255) ) + 1 } ( 1 .. 16 );
|
||||||
|
my $salt = en_base64( pack( 'c[16]', @salt_bytes ) );
|
||||||
|
|
||||||
|
return bcrypt( $password, '$2a$12$' . $salt );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_password {
|
||||||
|
my ( $password, $hash ) = @_;
|
||||||
|
|
||||||
|
if ( bcrypt( $password, $hash ) eq $hash ) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
sub epoch_to_dt {
|
sub epoch_to_dt {
|
||||||
my ($epoch) = @_;
|
my ($epoch) = @_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue