1DBIx::Class::EncodedColUusmenr(3C)ontributed Perl DocumeDnBtIaxt:i:oCnlass::EncodedColumn(3)
2
3
4

NAME

6       DBIx::Class::EncodedColumn - Automatically encode columns
7

SYNOPSIS

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      => 59,
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 and other components
70       such as Timestamp. Core should always be last.
71
72          E.g:
73          __PACKAGE__->load_components(qw/EncodedColumn TimeStamp Core/);
74

DESCRIPTION

76       This DBIx::Class component can be used to automatically encode a
77       column's contents whenever the value of that column is set.
78
79       This module is similar to the existing DBIx::Class::DigestColumns, but
80       there is some key differences:
81
82       "DigestColumns" performs the encode operation on "insert" and "update",
83       and "EncodedColumn" performs the operation when the value is set, or on
84       "new".
85       "DigestColumns" supports only algorithms of the Digest family.
86       "EncodedColumn" employs a set of thin wrappers around different cipher
87       modules to provide support for any cipher you wish to use and wrappers
88       are very simple to write (typically less than 30 lines).
89       "EncodedColumn" supports having more than one encoded column per table
90       and each column can use a different cipher.
91       "Encode" adds only one item to the namespace of the object utilizing it
92       ("_column_encoders").
93
94       There is, unfortunately, some features that "EncodedColumn" doesn't
95       support.  "DigestColumns" supports changing certain options at runtime,
96       as well as the option to not automatically encode values on set. The
97       author of this module found these options to be non-essential and
98       omitted them by design.
99

Options added to add_column

101       If any one of these options is present the column will be treated as a
102       digest column and all of the defaults will be applied to the rest of
103       the options.
104
105   encode_enable => 1
106       Enable automatic encoding of column values. If this option is not set
107       to true any other options will become no-ops.
108
109   encode_check_method => $method_name
110       By using the encode_check_method attribute when you declare a column
111       you can create a check method for that column. The check method accepts
112       a plain text string, and returns a boolean that indicates whether the
113       digest of the provided value matches the current value.
114
115   encode_class
116       The class to use for encoding. Available classes are:
117
118       "Crypt::Eksblowfish::Bcrypt" - uses
119       DBIx::Class::EncodedColumn::Crypt::Eksblowfish::Bcrypt and requires
120       Crypt::Eksblowfish::Bcrypt to be installed
121       "Digest" - uses DBIx::Class::EncodedColumn::Digest requires Digest to
122       be installed as well as the algorithm required (Digest::SHA,
123       Digest::Whirlpool, etc)
124       "Crypt::OpenPGP" - DBIx::Class::EncodedColumn::Crypt::OpenPGP and
125       requires Crypt::OpenPGP to be installed
126
127       Please see the relevant class's documentation for information about the
128       specific arguments accepted by each and make sure you include the
129       encoding algorithm (e.g. Crypt::OpenPGP) in your application's
130       requirements.
131

EXTENDED METHODS

133       The following DBIx::Class::ResultSource method is extended:
134
135       register_column - Handle the options described above.
136
137       The following DBIx::Class::Row methods are extended by this module:
138
139       new - Encode the columns on new() so that copy and create DWIM.
140       set_column - Encode values whenever column is set.
141

SEE ALSO

143       DBIx::Class::DigestColumns, DBIx::Class, Digest
144

AUTHOR

146       Guillermo Roditi (groditi) <groditi@cpan.org>
147
148       Inspired by the original module written by Tom Kirkpatrick (tkp)
149       <tkp@cpan.org> featuring contributions from Guillermo Roditi (groditi)
150       <groditi@cpan.org> and Marc Mims <marc@questright.com>
151

CONTRIBUTORS

153       jshirley - J. Shirley <cpan@coldhardcode.com>
154
155       kentnl - Kent Fredric <kentnl@cpan.org>
156
157       mst - Matt S Trout <mst@shadowcat.co.uk>
158
159       wreis - Wallace reis <wreis@cpan.org>
160
162       Copyright (c) the DBIx::Class::EncodedColumn "AUTHOR" and
163       "CONTRIBUTORS" as listed above.
164

LICENSE

166       This library is free software and may be distributed under the same
167       terms as perl itself.
168
169
170
171perl v5.28.0                      2016-06-01     DBIx::Class::EncodedColumn(3)
Impressum