Add authentication cache
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 8 Feb 2014 20:47:54 +0000 (22:47 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 8 Feb 2014 20:47:54 +0000 (22:47 +0200)
app.psgi

index 5bed878e4767c9806ea4aeba7e533b3278f68ba6..b1bd530dffa5fb4db7bb074a0005b5bb8a757921 100644 (file)
--- a/app.psgi
+++ b/app.psgi
@@ -7,6 +7,7 @@ use Gruntmaster::Data;
 use Plack::App::Gruntmaster;
 use Plack::Builder;
 use Plack::Request;
+use Digest::SHA qw/sha256/;
 
 $Apache2::AuthzCaps::rootdir = $Apache2::Authen::Passphrase::rootdir;
 my $word = qr,(\w+),a;
@@ -42,12 +43,23 @@ sub require_admin {
        }
 }
 
+my %authen_cache;
+
 sub authenticate {
        my ($user, $pass, $env) = @_;
+       my $cache_key = sha256 "$user:$pass";
+       my $time = $authen_cache{$cache_key} // 0;
+       if ($time >= time - 300) {
+               return 1;
+       } else {
+               delete $authen_cache{$cache_key};
+       }
+
        return unless eval {
                pwcheck $user, $pass;
                1
        };
+       $authen_cache{$cache_key} = time;
 
        return if $env->{'gruntmaster.reqadmin'} && !hascaps $user, 'gmadm';
        1
This page took 0.011123 seconds and 4 git commands to generate.