1DBIx::Class::EncodedColUusmenr(3Cpomn)tributed Perl DocuDmBeInxt:a:tCiloanss::EncodedColumn(3pm)
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   encode_column => 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

EXTENDED METHODS

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

SEE ALSO

139       DBIx::Class::DigestColumns, DBIx::Class, Digest
140

AUTHOR

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

CONTRIBUTORS

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

LICENSE

162       This library is free software and may be distributed under the same
163       terms as perl itself.
164
165
166
167perl v5.30.0                      2019-09-20   DBIx::Class::EncodedColumn(3pm)
Impressum