Hi Guys,
There is probably a simple solution... but got a little stuck... So I am using Class::DBI
I pass in the information I want to save in the database which in this case is also information which I want encrypted. I have a encryption function and I simply want to encrypt the data BEFORE it gets inserted into the DB. I thought I could simply add a 'before_set_$column' trigger and alter the value of one field and let it be updated... but once I update the data using the accessors... it calls the function again recursively... which isnt really helpful... what is the correct way to do it ?
I have so far (and doesnt work)
package Austin::DB::CreditCard;
use strict;
use warnings;
use Austin::DB;
use base qw/Austin::DB/;
use Austin::SUP::Helpers qw/encrypt/;
use Data::Dumper;
Austin::DB::CreditCard->table('cc_payment');
Austin::DB::CreditCard->columns(All => qw/trip_id cc_type cc_name cc_n
+umber expiry issue_no sec_code/);
Austin::DB::CreditCard->autoupdate(0);
__PACKAGE__->add_trigger( before_set_cc_number => \&do_encryption);
sub do_encryption {
my $self = shift;
my $encrypted = encrypt('local', $self->cc_number, getlogin());
$self->cc_number($encrypted);
}
1;
And then simply insert...
Austin::DB::CreditCard->insert(\%info);
Please no comments on storing cc info in a DB... at this point we do not have a choice and thats beyond my control
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.