NAME

DBIx::Class::CryptColumn - Automatically hash password/passphrase columns

VERSION

version 0.001

SYNOPSIS

__PACKAGE__->load_components(qw(CryptColumn));

__PACKAGE__->add_columns(
    id => {
        data_type         => 'integer',
        is_auto_increment => 1,
    },
    passphrase => {
        data_type          => 'text',
        inflate_passphrase => {
            encoder        => 'Argon2',
            verify_method  => 'verify_passphrase',
            rehash_method  => 'passphrase_needs_rehash',
        },
    },
);

__PACKAGE__->set_primary_key('id');

In application code:

# 'plain' will automatically be hashed using the specified passphrase_class
# and passphrase_args. The result of the hashing will stored in the
# specified encoding
$rs->create({ passphrase => 'plain' });

my $row = $rs->find({ id => $id });
my $passphrase = $row->passphrase; # Crypt::Passphrase::PassphraseHash object

if ($row->verify_passphrase($input)) {
  if ($row->passphrase_needs_rehash) {
    $row->update({ passphrase => $input });
  }
  ...
}

$row->passphrase('new passphrase');

DESCRIPTION

This component can be used to automatically hash password columns using any scheme supported by Crypt::Passphrase whenever the value of these columns is changed.

If the verify_method option is set it adds a method with that name to verify if a password matches the known hash, and likewise rehash_method will add a method for checking if a password needs to be rehashed.

METHODS

register_column

Chains with the register_column method in DBIx::Class::Row, and sets up passphrase columns according to the options documented above. This would not normally be directly called by end users.

set_column

Hash a passphrase column whenever it is set.

new

Hash all passphrase columns on new() so that copy(), create(), and others DWIM.

SEE ALSO

DBIx::Class::PassphraseColumn

DBIx::Class::EncodedColumn

AUTHOR

Leon Timmermans <leont@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by Leon Timmermans.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.