Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Class::DBI - performing action on column before it is used or saved

by edoc (Chaplain)
on Dec 20, 2003 at 00:24 UTC ( #315960=note: print w/replies, xml ) Need Help??


in reply to Class::DBI - performing action on column before it is used or saved

No guarentees that this is the best solution (in fact I kinda doubt it), but.. I would probably look at using before_create & before_update triggers, TEMP column, and overriding the search method. Beware though, there may still be issues with this method when another class interacts with this one automatically through relationships (I haven't dug deep enough to work out all the bits yet...)

__PACKAGE__->columns( TEMP => qw/ password / ); __PACKAGE__->add_trigger(before_create => sub { my ($self, %args) = @_; $self->{enc_pass} = $self->encrypt_password($self->{p +assword}); }); __PACKAGE__->add_trigger(before_update => sub { my ($self, %args) = @_; $self->enc_pass = $self->encrypt_password( $self->pas +sword ); }); sub search{ my ($self, %query) = @_; my @results = $self->SUPER::search( %query ); foreach my $result(@results){ $result->password( $self->decrypt_password( $result->encpass ) ); } }

$object->password should be used to get/set the plaintext password, while in the database it is encrypted an stored as enc_pass.

cheers,

J

  • Comment on Re: Class::DBI - performing action on column before it is used or saved
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315960]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2022-01-26 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (69 votes). Check out past polls.

    Notices?