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

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

by duct_tape (Hermit)
on Dec 19, 2003 at 21:17 UTC ( [id://315923]=note: print w/replies, xml ) Need Help??


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

I agree, however this isn't for use in checking a password that a user supplied. It's for listing passwords that are stored in the database for an application that manages host information. Which is why I am using Blowfish to encrypt them instead of doing a SHA1 or MD5 hash.

Also in this database are IP addresses that have been stored in a packed() format (by a previous developer). So my question also applies to them, and is not just strictly for the passwords.

IE:
The ip needs to be unpacked when it is read from the database, and then packed again before it is stored. So that I can keep my CDBI code transparent to the fact that this stuff is going on behind the scenes:

# to find the row that has this ip. my $obj = MyModule->search(ip => "127.0.0.1"); # or to print out the ip print $obj->ip; # or to update the ip... $obj->ip("192.168.0.1"); $obj->update();

I suppose I can always make methods like decode_ip, encode_ip, encrypt_password, etc... I just thought it'd be good to have it part of my CDBI class to make sure that the data gets written into the database in the correctly (ie: no passwords accidentally stored unecrypted because of a forgotten method call)

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

Replies are listed 'Best First'.
Re^5: Class::DBI - performing action on column before it is used or saved
by hardburn (Abbot) on Dec 19, 2003 at 21:39 UTC

    For IP addresses, I would have them inflate to a NetAddr::IP object:

    use NetAddr::IP; __PACKAGE__->has_a( ip_addr => 'NetAddr::IP' inflate => sub { my $packed = shift; # Unpack the IP addr here into $ip and $netmask return NetAddr::IP->new( $ip, $netmask ); }, deflate => sub { my $addr = shift; # Take the NetAddr::IP instance and pack it # into $packed return $packed; }, );

    Using Class::DBI = Good
    Using Class::DBI with inflation of many fields to objects = Better (usually)

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-23 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found