| 1 | # CGI::Session::ID::sha512 copyright 2008 Michael De Soto. This program is | ||
| 2 | # distributed under the terms of the GNU General Public License, version 3. | ||
| 3 | # | ||
| 4 | # $Id: sha512.pm 7 2008-11-04 04:27:03Z desoto@cpan.org $ | ||
| 5 | |||
| 6 | package CGI::Session::ID::sha512; | ||
| 7 | |||
| 8 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 1 | ▶ | use Digest::SHA; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 1 | ▶ | use CGI::Session::ErrorHandler; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | 1 | $CGI::Session::ID::sha512::VERSION = '1.01'; | |
| 15 | 1 | @CGI::Session::ID::sha512::ISA = qw/CGI::Session::ErrorHandler/; | |
| 16 | |||
| 17 | 1 | *generate = \&generate_id; | |
| 18 | 0 | ▶ | sub generate_id { |
|
Subroutine
generate_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 19 | 0 | my $sha = Digest::SHA->new(512); | |
| 20 | 0 | $sha->add($$ , time() , rand(time)); | |
| 21 | 0 | return $sha->hexdigest(); | |
| 22 | } | ||
| 23 | |||
| 24 | 1 | 1; | |
| 25 | |||
| 26 | =pod | ||
| 27 | |||
| 28 | =head1 NAME | ||
| 29 | |||
| 30 | CGI::Session::ID::sha512 - CGI::Session ID driver for generating SHA-512 based IDs | ||
| 31 | |||
| 32 | =head1 SYNOPSIS | ||
| 33 | |||
| 34 | use CGI::Session; | ||
| 35 | $session = new CGI::Session('id:sha512', undef); | ||
| 36 | |||
| 37 | =head1 DESCRIPTION | ||
| 38 | |||
| 39 | Use this module to generate SHA-512 encoded hexadecimal IDs for L<CGI::Session> | ||
| 40 | objects. This library does not require any arguments. To use it, add | ||
| 41 | C<id:sha512> to the DSN string when creating L<CGI::Session> objects. | ||
| 42 | |||
| 43 | =head2 Keep in mind | ||
| 44 | |||
| 45 | Keep in mind that a SHA-512 encoded hexadecimal string will have 128 characters. | ||
| 46 | Don't forget to take this into account when using a database to store your | ||
| 47 | session. For example, when using the default table layout with MySQL you'd want | ||
| 48 | to create a table like: | ||
| 49 | |||
| 50 | CREATE TABLE sessions ( | ||
| 51 | id CHAR(128) NOT NULL PRIMARY KEY, | ||
| 52 | a_session NOT NULL, | ||
| 53 | ); | ||
| 54 | |||
| 55 | =head1 CAVEATS | ||
| 56 | |||
| 57 | There are no caveats with this module, but rather with the way L<CGI::Session> | ||
| 58 | loads this module: | ||
| 59 | |||
| 60 | =head2 DSN string converted to lower case | ||
| 61 | |||
| 62 | For in depth discourse about this, please read the L<CGI::Session::ID::sha> | ||
| 63 | documentation. | ||
| 64 | |||
| 65 | =head1 SEE ALSO | ||
| 66 | |||
| 67 | L<CGI::Session>, L<Digest::SHA>, and our Web site: | ||
| 68 | L<http://code.google.com/p/perl-cgi-session-id-sha/>. | ||
| 69 | |||
| 70 | |||
| 71 | =head1 AUTHOR | ||
| 72 | |||
| 73 | Michael De Soto, E<lt>desoto@cpan.orgE<gt> | ||
| 74 | |||
| 75 | =head1 COPYRIGHT AND LICENSE | ||
| 76 | |||
| 77 | Copyright (C) 2008 Michael De Soto. All rights reserved. | ||
| 78 | |||
| 79 | This program is free software: you can redistribute it and/or modify it under | ||
| 80 | the terms of the GNU General Public License as published by the Free Software | ||
| 81 | Foundation, either version 3 of the License, or (at your option) any later | ||
| 82 | version. | ||
| 83 | |||
| 84 | This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 85 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
| 86 | PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 87 | |||
| 88 | You should have received a copy of the GNU General Public License along with | ||
| 89 | this program. If not, see L<http://www.gnu.org/licenses/>. | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||