Add a method that generates a reset HMAC to User.pm
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 16 Feb 2015 14:44:37 +0000 (16:44 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 16 Feb 2015 14:44:37 +0000 (16:44 +0200)
Makefile.PL
lib/Gruntmaster/Data/Result/User.pm

index 2207e58ac893c04b1e73f32b8ebfe5c8f7c9c411..d260b0f37480b363e0eae7566a8f55d1514e8d32 100644 (file)
@@ -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
index f961af915c18a8c6ea47b64c050e826663a9bb4c..35c6675519435f103ac047c76d968978238b9eec 100644 (file)
@@ -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__
This page took 0.012034 seconds and 4 git commands to generate.