ispman/lib/CGI/Session/ID Incr.pm,NONE,1.1 MD5.pm,NONE,1.1 SHA1.pm,NONE,1.1
Joerg Delker <[email protected]>
| Newsgroups | gmane.comp.isp.ispman.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ispman/ispman/lib/CGI/Session/ID
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8028/ID
Added Files:
Incr.pm MD5.pm SHA1.pm
Log Message:
2nd (hopefully complete) part of CGI::Session upgrade
--- NEW FILE: SHA1.pm ---
package CGI::Session::ID::SHA1;
# $Id: SHA1.pm,v 1.1 2004/07/08 09:12:30 jdelker Exp $
use strict;
use Digest::SHA1;
use vars qw($VERSION);
($VERSION) = '$Revision: 1.1 $' =~ m/Revision:\s*(\S+)/;
sub generate_id {
my $self = shift;
my $sha1 = new Digest::SHA1();
$sha1->add($$ , time() , rand(9999) );
return $sha1->hexdigest();
}
1;
=pod
=head1 NAME
CGI::Session::ID::SHA1 - SHA1 session id generator
=head1 SYNOPSIS
use CGI::Session;
$session = new CGI::Session("id:SHA1", undef);
=head1 DESCRIPTION
CGI::Session::ID::SHA1 is to generate SHA1 encoded hexidecimal random ids
using Digest::SHA1. The method does not require any arguments.
=head1 COPYRIGHT
Copyright (C) 2002 Sherzod Ruzmetov. All rights reserved.
This library is free software. You can modify and distribute it under the same terms as Perl itself.
=head1 AUTHOR
Sherzod Ruzmetov <[email protected]>
Feedbacks, suggestions and patches are welcome.
=head1 SEE ALSO
=over 4
=item *
L<Incr|CGI::Session::ID::Incr> - Auto Incremental ID generator
=item *
L<CGI::Session|CGI::Session> - CGI::Session manual
=item *
L<CGI::Session::Tutorial|CGI::Session::Tutorial> - extended CGI::Session manual
=item *
L<CGI::Session::CookBook|CGI::Session::CookBook> - practical solutions for real life problems
=item *
B<RFC 2965> - "HTTP State Management Mechanism" found at ftp://ftp.isi.edu/in-notes/rfc2965.txt
=item *
L<CGI|CGI> - standard CGI library
=item *
L<Apache::Session|Apache::Session> - another fine alternative to CGI::Session
=back
=cut
--- NEW FILE: Incr.pm ---
package CGI::Session::ID::Incr;
# $Id: Incr.pm,v 1.1 2004/07/08 09:12:30 jdelker Exp $
use strict;
use File::Spec;
use Carp "croak";
use Fcntl (':DEFAULT', ':flock');
use vars qw($VERSION);
($VERSION) = '$Revision: 1.1 $' =~ m/Revision:\s*(\S+)/;
sub generate_id {
my ($self, $options) = @_;
my $IDFile = $options->[1]->{IDFile} or croak "Don't know where to store the id";
my $IDIncr = $options->[1]->{IDIncr} || 1;
my $IDInit = $options->[1]->{IDInit} || 0;
unless (sysopen(FH, $IDFile, O_RDWR|O_CREAT, 0644) ) {
$self->error("Couldn't open IDFile=>$IDFile: $!");
return undef;
}
unless (flock(FH, LOCK_EX) ) {
$self->error("Couldn't lock IDFile=>$IDFile: $!");
return undef;
}
my $ID = <FH> || $IDInit;
unless ( seek(FH, 0, 0) ) {
$self->error("Couldn't seek IDFile=>$IDFile: $!");
return undef;
}
unless ( truncate(FH, 0) ) {
$self->error("Couldn't trunated IDFile=>$IDFile: $!");
return undef;
}
$ID += $IDIncr;
print FH $ID;
unless ( close(FH) ) {
$self->error("Couldn't close IDFile=>$IDFile: $!");
return undef;
}
return $ID;
}
1;
=pod
=head1 NAME
CGI::Session::ID::Incr - CGI::Session ID driver
=head1 SYNOPSIS
use CGI::Session qw/-api3/;
$session = new CGI::Session("id:Incr", undef,
{ Directory => '/tmp',
IDFile => '/tmp/cgisession.id',
IDInit => 1000,
IDIncr => 2 });
=head1 DESCRIPTION
CGI::Session::ID::Incr is to generate auto incrementing Session IDs. Compare it with CGI::Session::ID::MD5, where session ids are truely random 32 character long strings.
CGI::Session::ID::Incr expects the following arguments passed to CGI::Session->new() as the third argument
=over 4
=item "IDFile"
Location where auto incremened IDs are stored. This attribute is required.
=item "IDInit"
Initial value of the ID if it's the first ID to be generated. For example, if you want the ID numbers to start with 1000 as opposed to 0, that's where you should set your value. Default is 0.
=item "IDIncr"
How many digits each number should increment by. For example, if you want the first generated id to start with 1000, and each subsequent id to increment by 10, set 'IDIncr' to '10'. Default is 1.
=back
=head1 COPYRIGHT
Copyright (C) 2002 Sherzod Ruzmetov. All rights reserved.
This library is free software. You can modify and distribute it under the same terms as Perl itself.
=head1 AUTHOR
Sherzod Ruzmetov <[email protected]>
Feedbacks, suggestions and patches are welcome.
=head1 SEE ALSO
=over 4
=item *
L<MD5|CGI::Session::ID::MD5> - MD5 ID generator
=item *
L<CGI::Session|CGI::Session> - CGI::Session manual
=item *
L<CGI::Session::Tutorial|CGI::Session::Tutorial> - extended CGI::Session manual
=item *
L<CGI::Session::CookBook|CGI::Session::CookBook> - practical solutions for real life problems
=item *
B<RFC 2965> - "HTTP State Management Mechanism" found at ftp://ftp.isi.edu/in-notes/rfc2965.txt
=item *
L<CGI|CGI> - standard CGI library
=item *
L<Apache::Session|Apache::Session> - another fine alternative to CGI::Session
=back
=cut
--- NEW FILE: MD5.pm ---
package CGI::Session::ID::MD5;
# $Id: MD5.pm,v 1.1 2004/07/08 09:12:30 jdelker Exp $
use strict;
use Digest::MD5;
use vars qw($VERSION);
($VERSION) = '$Revision: 1.1 $' =~ m/Revision:\s*(\S+)/;
sub generate_id {
my $self = shift;
my $md5 = new Digest::MD5();
$md5->add($$ , time() , rand(9999) );
return $md5->hexdigest();
}
1;
=pod
=head1 NAME
CGI::Session::ID::MD5 - default CGI::Session ID driver
=head1 SYNOPSIS
use CGI::Session qw/-api3/;
$session = new CGI::Session("id:MD5", undef,
{ Directory => '/tmp',
IDFile => '/tmp/cgisession.id',
IDInit => 1000,
IDIncr => 2 });
=head1 DESCRIPTION
CGI::Session::ID::MD5 is to generate MD5 encoded hexidecimal random ids.
The library does not require any arguments.
=head1 COPYRIGHT
Copyright (C) 2002 Sherzod Ruzmetov. All rights reserved.
This library is free software. You can modify and distribute it under the same terms as Perl itself.
=head1 AUTHOR
Sherzod Ruzmetov <[email protected]>
Feedbacks, suggestions and patches are welcome.
=head1 SEE ALSO
=over 4
=item *
L<Incr|CGI::Session::ID::Incr> - Auto Incremental ID generator
=item *
L<CGI::Session|CGI::Session> - CGI::Session manual
=item *
L<CGI::Session::Tutorial|CGI::Session::Tutorial> - extended CGI::Session manual
=item *
L<CGI::Session::CookBook|CGI::Session::CookBook> - practical solutions for real life problems
=item *
B<RFC 2965> - "HTTP State Management Mechanism" found at ftp://ftp.isi.edu/in-notes/rfc2965.txt
=item *
L<CGI|CGI> - standard CGI library
=item *
L<Apache::Session|Apache::Session> - another fine alternative to CGI::Session
=back
=cut
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com