Apache-AutoLogin
view release on metacpan or search on metacpan
AutoLogin.pm view on Meta::CPAN
$string=$cipher->encrypt($string);
return $string;
}
sub decrypt_aes {
my ($string, $key)=@_;
# keysize() is 32, but 24 and 16 are also possible
# blocksize() is 16
## The string must have 16 bytes blocks.
if (length($string) % 16 !=0)
{
return "";
}
my $cipher = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC;
# decrypt it
my $decrypted=$cipher->decrypt($string);
# Chop of the last 32 bytes (this is the md5 checksum)
# and calculate checksum
## Check if the string is longer than 32 bytes
if (length ($decrypted)<32)
{
return "";
}
## Alter the string (chop of the last 32 bytes
my $checksum=substr($decrypted,-32);
$decrypted=substr($decrypted,0,(length($decrypted)-32));
## If the checksum is invalid return this
if ($checksum ne md5_hex($decrypted))
{
return "";
}
## chop of the random data
my $char=" ";
while($char ne ':' and $char ne '')
{
$char=chop($decrypted);
}
## If char is eq to '' then there were no credentials, etc. in the string...
if ($char eq '')
{
return '';
}
return $decrypted;
}
1;
__END__
# Below is stub documentation for your module. You better edit it!
=head1 NAME
Apache::AutoLogin - Automatic login module based on encrypted cookies for sites using basic authentication.
=head1 SYNOPSIS
# In httpd.conf or .htaccess put it just
# before your basic authentication module
# It has the be invoked as a PerlAccessHandler,
# because this is just the phase
# before authentication!
<Location />
PerlModule Apache::AutoLogin
PerlAccessHandler Apache::AutoLogin
# Set the lifetime of the cookie in days
PerlSetVar AutoLoginCookieLifetimeInDays "3"
# The encryption key can have any length, but the longer the better
PerlSetVar AutoLoginEncryptionKey "abcdefghijklmnopqrstuvwxyz123456"
# set the logout page: Important, make
# sure that you specify something
# that gets not cached by proxies, or
# else the cookie won't be invalidated.
PerlSetVar AutoLoginLogoutPage "/logout.php"
# The name of the cookie
PerlSetVar AutoLoginAuthName "AutoLogin rulez"
# Here comes the basic authentication
# module of any flavour. Apache::AutoLogin
# has been tested with AuthPAM and AuthLDAP
AuthType Basic
AuthName "Apache_AutoLogin example"
AuthPAM_Enabled on
require valid-user
</Location>
# In this example make sure logout.php
# can be viewed by the client without authentication!
<Location /logout.php>
PerlModule Apache::AutoLogin
PerlAccessHandler Apache::AutoLogin
PerlSetVar AutoLoginCookieLifetimeInDays "3"
## Anything as a key, is not important, cause it will by a random key
PerlSetVar AutoLoginEncryptionKey "abcdefghijklmnopqrstuvwxyz123456"
PerlSetVar AutoLoginLogoutPage "/logout.php"
PerlSetVar AutoLoginAuthName "AutoLogin rulez"
( run in 0.639 second using v1.01-cache-2.11-cpan-39bf76dae61 )