diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-03-06 17:59:00 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-03-06 17:59:00 +0100 |
commit | 058d93a6fd9f186c46ff8f53a444a914fb226d8a (patch) | |
tree | 6bb0ac10b74786d5e6b61e6ce5f3f05f99028907 | |
parent | 8057c16cc438769671f5d47aef39e8017b430d19 (diff) |
add password hashing
-rwxr-xr-x | index.pl | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -3,6 +3,7 @@ use Mojolicious::Lite; use Mojolicious::Plugin::Authentication; use Cache::File; +use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); use DateTime; use DBI; 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 { my ($epoch) = @_; |