Apache-Session-Generate-Random
view release on metacpan or search on metacpan
lib/Apache/Session/Generate/Random.pm view on Meta::CPAN
our $VERSION = '0.002002';
# ABSTRACT: use system randomness for generating session ids
sub generate {
my ($session) = @_;
return $session->{'data'}->{'_session_id'} = unpack( 'H*', Crypt::SysRandom::random_bytes(20) );
}
sub validate {
my ($session) = @_;
if ( $session->{data}->{_session_id} =~ /^[0-9a-f]{40}$/ ) {
return $session->{data}->{_session_id};
}
die "Invalid session ID: " . $session->{data}->{_session_id};
}
1;
lib/Apache/Session/Generate/Random.pm view on Meta::CPAN
Generate => 'Random',
Serialize => 'Base64',
};
=head1 DESCRIPTION
This module extends L<Apache::Session> to create secure random session ids using the system's source of randomness.
=for Pod::Coverage generate
=for Pod::Coverage validate
=head1 SEE ALSO
L<Apache::Session>
L<Crypt::SysRandom>
=head1 SUPPORT
Only the latest version of this module will be supported.
lib/Apache/SessionX/Generate/Random.pm view on Meta::CPAN
use Apache::Session::Generate::Random;
our $VERSION = '0.002002';
# ABSTRACT: use system randomness for generating session ids
BEGIN {
*generate = \&Apache::Session::Generate::Random::generate;
*validate = \&Apache::Session::Generate::Random::validate;
}
1;
__END__
=pod
lib/Apache/SessionX/Generate/Random.pm view on Meta::CPAN
use Apache::SessionX::Generate::Random;
$id = Apache::SessionX::Generate::Random::generate($string);
=head1 DESCRIPTION
This module extends L<Apache::SessionX> to create secure random session ids using the system's source of randomness.
=for Pod::Coverage generate
=for Pod::Coverage validate
=head1 SEE ALSO
L<Apache::SessionX>
L<Crypt::SysRandom>
=head1 SUPPORT
Only the latest version of this module will be supported.
t/01-simple.t view on Meta::CPAN
use Test::More;
use Apache::Session::Generate::Random;
my %session;
Apache::Session::Generate::Random::generate( \%session );
ok my $id = $session{data}->{_session_id}, "generated a session_id";
is Apache::Session::Generate::Random::validate( \%session ), $id, "validated session_id";
done_testing;
t/02-sessionx.t view on Meta::CPAN
use Test::More;
use Apache::SessionX::Generate::Random;
my %session;
Apache::SessionX::Generate::Random::generate( \%session );
ok my $id = $session{data}->{_session_id}, "generated a session_id";
is Apache::SessionX::Generate::Random::validate( \%session ), $id, "validated session_id";
done_testing;
( run in 1.289 second using v1.01-cache-2.11-cpan-140bd7fdf52 )