line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# CGI::Session::ID::sha256 copyright 2008 Michael De Soto. This program is |
2
|
|
|
|
|
|
|
# distributed under the terms of the GNU General Public License, version 3. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: sha256.pm 7 2008-11-04 04:27:03Z desoto@cpan.org $ |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package CGI::Session::ID::sha256; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
34762
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
71
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
4
|
use Digest::SHA; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
12
|
1
|
|
|
1
|
|
5
|
use CGI::Session::ErrorHandler; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
117
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$CGI::Session::ID::sha256::VERSION = '1.01'; |
15
|
|
|
|
|
|
|
@CGI::Session::ID::sha256::ISA = qw/CGI::Session::ErrorHandler/; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
*generate = \&generate_id; |
18
|
|
|
|
|
|
|
sub generate_id { |
19
|
0
|
|
|
0
|
0
|
|
my $sha = Digest::SHA->new(256); |
20
|
0
|
|
|
|
|
|
$sha->add($$ , time() , rand(time)); |
21
|
0
|
|
|
|
|
|
return $sha->hexdigest(); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
1; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=pod |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
CGI::Session::ID::sha256 - CGI::Session ID driver for generating SHA-256 based IDs |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use CGI::Session; |
35
|
|
|
|
|
|
|
$session = new CGI::Session('id:sha256', undef); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Use this module to generate SHA-256 encoded hexadecimal IDs for L |
40
|
|
|
|
|
|
|
objects. This library does not require any arguments. To use it, add |
41
|
|
|
|
|
|
|
C to the DSN string when creating L objects. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 Keep in mind |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Keep in mind that a SHA-256 encoded hexadecimal string will have 64 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(64) 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 |
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 |
63
|
|
|
|
|
|
|
documentation. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SEE ALSO |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
L, L, and our Web site: |
68
|
|
|
|
|
|
|
L. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Michael De Soto, Edesoto@cpan.orgE |
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. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|