README
1NAME
2 DBIx::Class::DigestColumns - Automatic digest columns
3
4SYNOPSIS
5 In your DBIx::Class table class:
6
7 __PACKAGE__->load_components(qw/DigestColumns ... Core/);
8
9 #automatically generate a method "check_password" in result class
10 __PACKAGE__->add_columns(
11 'password' => {
12 data_type => 'char',
13 size => 32,
14 digest_check_method => 'check_password',
15 }
16 __PACKAGE__->digestcolumns(
17 columns => [qw/ password /],
18 algorithm => 'MD5',
19 encoding => 'base64',
20 dirty => 1,
21 auto => 1,
22 );
23
24 Note: The component needs to be loaded *before* Core.
25
26 Alternatively you could call each method individually
27
28 __PACKAGE__->digest_columns(qw/ password /);
29 __PACKAGE__->digest_algorithm('MD5');
30 __PACKAGE__->digest_encoding('base64');
31 __PACKAGE__->digest_dirty(1);
32 __PACKAGE__->digest_auto(1);
33
34DESCRIPTION
35 This DBIx::Class component can be used to automatically insert a message
36 digest of selected columns. By default DigestColumns will use
37 Digest::MD5 to insert a 128-bit hexadecimal message digest of the column
38 value.
39
40 The length of the inserted string will be 32 and it will only contain
41 characters from this set: '0'..'9' and 'a'..'f'.
42
43 If you would like to use a specific digest module to create your message
44 digest, you can set "digest_algorithm":
45
46 __PACKAGE__->digest_algorithm('SHA-1');
47
48Options added to add_column
49 digest_check_method => $method_name
50 By using the digest_check_method attribute when you declare a column you
51 can create a check method for that column. The check method accepts a
52 plain text string, performs the correct digest on it and returns a
53 boolean value indicating whether this method matches the
54 currently_stored value.
55
56 $row->password('old_password');
57 $row->update;
58 $row->password('new_password');
59 $row->check_password('new_password'); #returns true
60 $row->check_password('old_password'); #returns false
61 $row->update;
62
63METHODS
64 digestcolumns
65 __PACKAGE__->digestcolumns(
66 columns => [qw/ password /],
67 algorithm => $algorithm',
68 encoding => $encoding,
69 dirty => 1,
70 auto => 1,
71 );
72
73 Calls "digest_columns", "digest_algorithm", and "digest_encoding" and
74 "digest_auto" if the corresponding argument is defined.
75
76 register_column
77 Override the original register_column to handle the creation of check
78 methods.
79
80 digest_columns
81 Takes a list of columns to be convert to a message digest during insert.
82
83 __PACKAGE__->digest_columns(qw/ password /);
84
85 digest_algorithm
86 Takes the name of a digest algorithm to be used to calculate the message
87 digest.
88
89 __PACKAGE__->digest_algorithm('SHA-1');
90
91 If a suitible digest module could not be loaded an exception will be
92 thrown.
93
94 Supported digest algorithms are:
95
96 MD5
97 MD4
98 MD2
99 SHA-1
100 SHA-256
101 SHA-384
102 SHA-512
103 CRC-16
104 CRC-32
105 CRC-CCITT
106 HMAC-SHA-1
107 HMAC-MD5
108 Whirlpool
109 Adler-32
110
111 digest_algorithm defaults to "MD5".
112
113 digest_encoding
114 Selects the encoding to use for the message digest.
115
116 __PACKAGE__->digest_encoding('base64');
117
118 Possilbe encoding schemes are:
119
120 binary
121 hex
122 base64
123
124 digest_encoding defaults to "hex".
125
126 _get_digest_string $value
127 Handles the actual encoding of column values into digests. When given a
128 $value it will return the digest string for that value. This is the
129 method used by "_digest_column_values" So you can use it to create an
130 identical digest if you need one for comparison (e.g. password
131 authentication).
132
133 _digest_column_values
134 Go through the columns and digest the values that need it.
135
136 This method is called by insert and update when automatic digests are
137 turned on. If dirty is enabled it will only digest the values of dirtied
138 columns.
139
140 digest_auto
141 __PACKAGE__->digest_auto(1);
142
143 Turns on and off automatic digest columns. When on, this feature makes
144 all UPDATEs and INSERTs automatically insert a message digest of
145 selected columns.
146
147 The default is for digest_auto is to be on.
148
149 digest_dirty
150 __PACKAGE__->digest_dirty(1);
151
152 Turns on and off the limiting of automatic digests to only dirty
153 columns. When on, only columns that have been dirtied will have their
154 values digested during UPDATEs and INSERTs. If auto is set to off this
155 option does nothing.
156
157 The default is for digest_dirty is to be off to mantain compatibility
158 with older versions of this module.
159
160EXTENDED METHODS
161 The following DBIx::Class::Row methods are extended by this module:-
162
163 insert
164 update
165
166SEE ALSO
167 DBIx::Class, Digest
168
169AUTHOR
170 Tom Kirkpatrick (tkp) <tkp@cpan.org>
171
172 With contributions from Guillermo Roditi (groditi) <groditi@cpan.org>
173 and Marc Mims <marc@questright.com>
174
175LICENSE
176 You may distribute this code under the same terms as Perl itself.
177
178