1DBIx::Class::EncodedColUusmenr(3C)ontributed Perl DocumeDnBtIaxt:i:oCnlass::EncodedColumn(3)
2
3
4
6 DBIx::Class::EncodedColumn - Automatically encode columns
7
9 In your DBIx::Class Result class (sometimes erroneously referred to as
10 the 'table' class):
11
12 __PACKAGE__->load_components(qw/EncodedColumn ... Core/);
13
14 #Digest encoder with hex format and SHA-1 algorithm
15 __PACKAGE__->add_columns(
16 'password' => {
17 data_type => 'CHAR',
18 size => 40,
19 encode_column => 1,
20 encode_class => 'Digest',
21 encode_args => {algorithm => 'SHA-1', format => 'hex'},
22 }
23
24 #SHA-1 / hex encoding / generate check method
25 __PACKAGE__->add_columns(
26 'password' => {
27 data_type => 'CHAR',
28 size => 40 + 10,
29 encode_column => 1,
30 encode_class => 'Digest',
31 encode_args => {algorithm => 'SHA-1', format => 'hex', salt_length => 10},
32 encode_check_method => 'check_password',
33 }
34
35 #MD5 / base64 encoding / generate check method
36 __PACKAGE__->add_columns(
37 'password' => {
38 data_type => 'CHAR',
39 size => 22,
40 encode_column => 1,
41 encode_class => 'Digest',
42 encode_args => {algorithm => 'MD5', format => 'base64'},
43 encode_check_method => 'check_password',
44 }
45
46 #Eksblowfish bcrypt / cost of 8/ no key_nul / generate check method
47 __PACKAGE__->add_columns(
48 'password' => {
49 data_type => 'CHAR',
50 size => 22,
51 encode_column => 1,
52 encode_class => 'Crypt::Eksblowfish::Bcrypt',
53 encode_args => { key_nul => 0, cost => 8 },
54 encode_check_method => 'check_password',
55 }
56
57 In your application code:
58
59 #updating the value.
60 $row->password('plaintext');
61 my $digest = $row->password;
62
63 #checking against an existing value with a check_method
64 $row->check_password('old_password'); #true
65 $row->password('new_password');
66 $row->check_password('new_password'); #returns true
67 $row->check_password('old_password'); #returns false
68
69 Note: The component needs to be loaded before Core.
70
72 This DBIx::Class component can be used to automatically encode a
73 column's contents whenever the value of that column is set.
74
75 This module is similar to the existing DBIx::Class::DigestColumns, but
76 there is some key differences:
77
78 "DigestColumns" performs the encode operation on "insert" and "update",
79 and "EncodedColumn" performs the operation when the value is set, or on
80 "new".
81 "DigestColumns" supports only algorithms of the Digest family.
82 "EncodedColumn" employs a set of thin wrappers around different cipher
83 modules to provide support for any cipher you wish to use and wrappers
84 are very simple to write (typically less than 30 lines).
85 "EncodedColumn" supports having more than one encoded column per table
86 and each column can use a different cipher.
87 "Encode" adds only one item to the namespace of the object utilizing it
88 ("_column_encoders").
89
90 There is, unfortunately, some features that "EncodedColumn" doesn't
91 support. "DigestColumns" supports changing certain options at runtime,
92 as well as the option to not automatically encode values on set. The
93 author of this module found these options to be non-essential and
94 omitted them by design.
95
97 If any one of these options is present the column will be treated as a
98 digest column and all of the defaults will be applied to the rest of
99 the options.
100
101 encode_enable => 1
102 Enable automatic encoding of column values. If this option is not set
103 to true any other options will become no-ops.
104
105 encode_check_method => $method_name
106 By using the encode_check_method attribute when you declare a column
107 you can create a check method for that column. The check method accepts
108 a plain text string, and returns a boolean that indicates whether the
109 digest of the provided value matches the current value.
110
111 encode_class
112 The class to use for encoding. Available classes are:
113
114 "Crypt::Eksblowfish::Bcrypt" - uses
115 DBIx::Class::EncodedColumn::Crypt::Eksblowfish::Bcrypt and requires
116 Crypt::Eksblowfish::Bcrypt to be installed
117 "Digest" - uses DBIx::Class::EncodedColumn::Digest requires Digest to
118 be installed as well as the algorithm required (Digest::SHA,
119 Digest::Whirlpool, etc)
120 "Crypt::OpenPGP" - DBIx::Class::EncodedColumn::Crypt::OpenPGP and
121 requires Crypt::OpenPGP to be installed
122
123 Please see the relevant class's documentation for information about the
124 specific arguments accepted by each and make sure you include the
125 encoding algorithm (e.g. Crypt::OpenPGP) in your application's
126 requirements.
127
129 The following DBIx::Class::ResultSource method is extended:
130
131 register_column - Handle the options described above.
132
133 The following DBIx::Class::Row methods are extended by this module:
134
135 new - Encode the columns on new() so that copy and create DWIM.
136 set_column - Encode values whenever column is set.
137
139 DBIx::Class::DigestColumns, DBIx::Class, Digest
140
142 Guillermo Roditi (groditi) <groditi@cpan.org>
143
144 Inspired by the original module written by Tom Kirkpatrick (tkp)
145 <tkp@cpan.org> featuring contributions from Guillermo Roditi (groditi)
146 <groditi@cpan.org> and Marc Mims <marc@questright.com>
147
149 kentnl - Kent Fredric <kentnl@cpan.org>
150
151 mst - Matt S Trout <mst@shadowcat.co.uk>
152
154 Copyright (c) 2008 - 2009 the DBIx::Class::EncodedColumn "AUTHOR" and
155 "CONTRIBUTORS" as listed above.
156
158 This library is free software and may be distributed under the same
159 terms as perl itself.
160
161
162
163perl v5.12.1 2010-08-27 DBIx::Class::EncodedColumn(3)