Egg::Model::Session::ID::MD5 - MD5 is used for session ID.


Egg-Plugin-SessionKit documentation Contained in the Egg-Plugin-SessionKit distribution.

Index


Code Index:

NAME

Top

Egg::Model::Session::ID::MD5 - MD5 is used for session ID.

SYNOPSIS

Top

  package MyApp::Model::Sesion;

  __PACKAGE__->startup(
   .....
   ID::MD5
   );

DESCRIPTION

Top

It is a component module to use the HEX value obtained with Digest::MD5 for session ID.

'id_length' is accepted to the configuration.

  __PACKAGE__->config(
    id_length => 32,
    );

It becomes 32 at the unspecification.

METHODS

Top

make_session_id

The value obtained by 'md5_hex' function of Digest::MD5 is returned.

valid_session_id (SESSION_ID)

The format of SESSION_ID is checked and the result is returned.

SEE ALSO

Egg::Release, Egg::Model::Session::Manager::TieHash, Digest::MD5, Time::HiRes,

AUTHOR

Top

Masatoshi Mizuno <lushe&64;cpan.org>

COPYRIGHT AND LICENSE

Top


Egg-Plugin-SessionKit documentation Contained in the Egg-Plugin-SessionKit distribution.

package Egg::Model::Session::ID::MD5;
#
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
#
# $Id: MD5.pm 256 2008-02-14 21:07:38Z lushe $
#
use strict;
use warnings;
use Carp qw/ croak /;
use Digest::MD5 qw/ md5_hex /;
use Time::HiRes qw/ gettimeofday /;

our $VERSION= '0.01';

sub _setup {
	my($class, $e)= @_;
	$class->config->{id_length} ||= 32;
	$class->next::method($e);
}
sub make_session_id {
	substr(
	  md5_hex( gettimeofday. {}. rand(1000). $$ ),
	  0, $_[0]->config->{id_length},
	  );
}
sub valid_session_id {
	my $self= shift;
	my $id= shift || croak q{I want session id.};
	my $len= $self->config->{id_length};
	$id=~m{^[a-f0-9]{$len}$} ? $id : (undef);
}

1;

__END__