=head1 NAME

Rose::DB::Object::MakeMethods::EKSBlowfish - Create Blowfish-specific object methods for Rose::DB::Object-derived objects.

=head1 VERSION

Version 0.01

=head1 SYNOPSIS

   package MyDBObject;

   our @ISA = qw(Rose::DB::Object);

   use Rose::DBx::Object::MakeMethods::EKSBlowfish(
   eksblowfish => 
      [
        'type' => 
        {
          cost      => 8,
          key_nul   => 0,
        },
      ],
   );

  ...

  $o = MyDBObject->new(...);

  $o->password('foobar');

  # Something like: "$2$08$NWgpob52QKA2fRUgCwB93O1qoHZGu/Kr9iGfI/2nhy9uc9R2IG9by"
  print $o->password_encrypted;

  print $o->password; # "foobar"
  print "ok" if($o->password_is('foobar'); # "ok"


=head1 DESCRIPTION

C<Rose::DB::Object::MakeMethods::EKSBlowfish> creates methods that deal with eksblowfish encrypted passwords.  It inherits from L<Rose::Object::MakeMethods>.  See the L<Rose::Object::MakeMethods> documentation to learn about the interface.  The method types provided by this module are described below.

All method types defined by this module are designed to work with objects that are subclasses of (or otherwise conform to the interface of) L<Rose::DB::Object>.  In particular, the object is expected to have a C<db> method that returns a L<Rose::DB>-derived object.  See the L<Rose::DB::Object> documentation for more details.

=head1 METHODS TYPES

=over 4

=item B<eksblowfish>

Create a family methods for handling eksblowfish encrypted passwords.

=over 4

=item Options

=over 4

=item C<cmp_suffix>

The string appended to the default method name to form the name of the comparison method.  Defaults to "_is".

=item C<encrypted_suffix>

The string appended to the default method name to form the name of the get/set method that handles the encrypted version of the CHKPASS value.  Defaults to "_encrypted".

=item C<hash_key>

The key inside the hash-based object to use for the storage of the unencrypted value.  Defaults to the name of the method.

The encrypted value is stored in a hash key with the same name, but with C<encrypted_suffix> appended.  

=back

=item Interfaces

=over 4

=item C<get_set>

Creates a family of methods for handling eksblowfish encrypted passwords.  The methods are:

=over 4

=item C<default>

The get/set method for the unencrypted value.  (This method uses the default method name.)  If called with no arguments, the unencrypted value is returned, if it is known.  If not, undef is returned.

If passed an argument that begins with "$", it is assumed to be an encrypted value and is stored as such.  Undef is returned, since it is not feasible to determine the unencrypted value based on the encrypted value.

If passed an argument that does not begin with "$", it is taken as the unencrypted value. 

=item C<encrypted>

The get/set method for the encrypted value.  The method name will be formed by concatenating the C<default> method name (above) and the value of the C<encrypted_suffix> option.

If called with no arguments, the encrypted value is returned, if it is known.  If not, undef is returned.

If passed an argument that begins with "$", it is assumed to be an encrypted value and is stored as such.  The unencrypted value is set to undef, since it is not feasible to determine the unencrypted value based on the encrypted value.  The encrypted value is returned.

If passed an argument that does not begin with "$", it is taken as the unencrypted value. =item C<comparison>

This method compares its argument to the unencrypted value and returns true if the two values are identical (string comparison), false if they are not, and undef if both the encrypted and unencrypted values are undefined.

=back

=back

=back

Example:

    package MyDBObject;

    use base qw(Rose::DB::Object);
    use Rose::DBx::Object::MakeMethods::EKSBlowfish(
    eksblowfish => 
       [
         'type' => 
         {
           cost      => 8,
           key_nul   => 0,
         },
       ],
    );
    
    __PACKAGE__->meta->setup(
        db => $db,
        table => 'users',
    
        columns => [
            id              => { type => 'serial',    not_null => 1 },
            name            => { type => 'varchar',   length   => 255, not_null => 1 },
            password        => { type => 'eksblowfish', not_null => 1, },
        ],
    
        primary_key_columns => ['id'],
    
        unique_key => ['name'],
    
    );

    ...

    $o = MyDBObject->new(...);

    $o->password('blah');

    $o->password('foobar');

    # Something like: "$2$08$ft6IhGIrQz1uDJiv6nD7sePuQEfcpb7excBQnDGu2GmDuk7kb5Ie6"
    print $o->password_encrypted;

    print $o->get_password; # "foobar"
    print $o->password;     # "foobar"
    print "ok" if($o->password_is('foobar'); # "ok"

=item B<_encrypted>

the encryption generator

=back    

=head1 AUTHOR

Holger Rupprecht (holger.rupprecht@gmx.de)

=head1 LICENSE

Copyright (c) 2010 by Holger Rupprecht.  All rights reserved.  This program is
free software; you can redistribute it and/or modify it under the same terms
as Perl itself.


