From: Marius Gavrilescu Date: Mon, 16 Feb 2015 14:44:37 +0000 (+0200) Subject: Add a method that generates a reset HMAC to User.pm X-Git-Tag: 5999.000_014~69 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=54bc1dffe205d7d3514dacd57a661a110b83943f;p=gruntmaster-data.git Add a method that generates a reset HMAC to User.pm --- diff --git a/Makefile.PL b/Makefile.PL index 2207e58..d260b0f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -18,10 +18,12 @@ WriteMakefile( Authen::Passphrase 0 Authen::Passphrase::BlowfishCrypt 0 + Bytes::Random::Secure 0 Class::Method::Modifiers 0 Date::Parse 0 DBIx::Class 0 DBD::Pg 0 + Digest::SHA 0 File::Slurp 0 IO::Prompter 0 Lingua::EN::Inflect 0 diff --git a/lib/Gruntmaster/Data/Result/User.pm b/lib/Gruntmaster/Data/Result/User.pm index f961af9..35c6675 100644 --- a/lib/Gruntmaster/Data/Result/User.pm +++ b/lib/Gruntmaster/Data/Result/User.pm @@ -236,7 +236,9 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-02-10 18:42:04 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L/ExLdA0pkJ1DeM+RzlDjw +use Bytes::Random::Secure qw/random_bytes/; use Class::Method::Modifiers qw/after/; +use Digest::SHA qw/hmac_sha1_base64/; after qw/insert update delete/ => sub { my ($self) = @_; @@ -261,6 +263,15 @@ sub set_passphrase { )->as_rfc2307}); } +my $hmackey = $ENV{GRUNTMASTER_HMAC_KEY}; + +sub make_reset_hmac { + my ($self, $expire) = @_; + $expire //= time + 60 * 60; + $hmackey //= random_bytes 512; + hmac_sha1_base64 $self->id . " $expire " . $self->passphrase, $hmackey; +} + 1; __END__