Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Automatically encrypt the password column.

  • Loading branch information...
commit 1aa3b91f13f1a41acb808c39cf9b7c4ae5ee2b16 1 parent f47461a
@davorg authored
View
5 Build.PL
@@ -7,8 +7,9 @@ my $build = Module::Build->new(
DBIx::Class => 0,
DBD::mysql => 0,
Moose => 0,
- MooseX::MarkAsMethods => 0,
- MooseX::NonMoose => 0,
+ MooseX::MarkAsMethods => 0,
+ MooseX::NonMoose => 0,
+ DBIx::Class::EncodedColumn => 0,
},
build_requires => {
Test::Class => 0,
View
36 bin/dump_dbic
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use DBIx::Class::Schema::Loader qw[make_schema_at];
+
+make_schema_at(
+ 'Lystyng::Schema', {
+ dump_directory => 'lib',
+ use_moose => 1,
+ components => [ 'EncodedColumn' ],
+ custom_column_info => \&encode_password,
+ }, [
+ "dbi:mysql:dbname=$ENV{LYSTYNG_DB_NAME};host=$ENV{LYSTYNG_DB_SERVER}",
+ $ENV{LYSTYNG_DB_USER}, $ENV{LYSTYNG_DB_PASS},
+ ],
+);
+
+sub encode_password {
+ my ($table, $column_name) = @_;
+
+ if ($column_name eq 'password') {
+ return {
+ encode_column => 1,
+ encode_class => 'Digest',
+ encode_args => {
+ algorithm => 'SHA-1',
+ format => 'hex',
+ salt_length => 10,
+ },
+ encode_check_method => 'check_password',
+ };
+ }
+}
View
16 lib/Lystyng/Schema/Result/List.pm
@@ -18,6 +18,18 @@ use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';
+=head1 COMPONENTS LOADED
+
+=over 4
+
+=item * L<DBIx::Class::EncodedColumn>
+
+=back
+
+=cut
+
+__PACKAGE__->load_components("EncodedColumn");
+
=head1 TABLE: C<list>
=cut
@@ -115,8 +127,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-01-07 22:12:36
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BxQAjsxwfUnZNtVCJPzXjg
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-01-30 20:13:57
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3eYA3YhJdL90HQRfNN07EA
# You can replace this text with custom code or comments, and it will be preserved on regeneration
View
16 lib/Lystyng/Schema/Result/ListItem.pm
@@ -18,6 +18,18 @@ use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';
+=head1 COMPONENTS LOADED
+
+=over 4
+
+=item * L<DBIx::Class::EncodedColumn>
+
+=back
+
+=cut
+
+__PACKAGE__->load_components("EncodedColumn");
+
=head1 TABLE: C<list_item>
=cut
@@ -92,8 +104,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-01-07 22:12:36
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RoyFBd+PBGmWt1HIJH1FZw
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-01-30 20:13:57
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JdNndq1NJ/hzKunvCfj99g
# You can replace this text with custom code or comments, and it will be preserved on regeneration
View
30 lib/Lystyng/Schema/Result/User.pm
@@ -18,6 +18,18 @@ use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';
+=head1 COMPONENTS LOADED
+
+=over 4
+
+=item * L<DBIx::Class::EncodedColumn>
+
+=back
+
+=cut
+
+__PACKAGE__->load_components("EncodedColumn");
+
=head1 TABLE: C<user>
=cut
@@ -47,6 +59,10 @@ __PACKAGE__->table("user");
=head2 password
data_type: 'char'
+ encode_args: {algorithm => "SHA-1",format => "hex",salt_length => 10}
+ encode_check_method: 'check_password'
+ encode_class: 'Digest'
+ encode_column: 1
is_nullable: 0
size: 64
@@ -60,7 +76,15 @@ __PACKAGE__->add_columns(
"email",
{ data_type => "varchar", is_nullable => 0, size => 200 },
"password",
- { data_type => "char", is_nullable => 0, size => 64 },
+ {
+ data_type => "char",
+ encode_args => { algorithm => "SHA-1", format => "hex", salt_length => 10 },
+ encode_check_method => "check_password",
+ encode_class => "Digest",
+ encode_column => 1,
+ is_nullable => 0,
+ size => 64,
+ },
);
=head1 PRIMARY KEY
@@ -93,8 +117,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-01-07 22:12:36
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:K6jCcJvzi8cOrpjW0pgYpw
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-01-30 20:20:50
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dOskylIQblron+9s87lFpw
# You can replace this text with custom code or comments, and it will be preserved on regeneration
View
5 t/Test/Lystyng/Schema/Result/User.pm
@@ -26,15 +26,16 @@ sub basic : Tests {
ok($user, 'Got another user');
isa_ok($user, 'Lystyng::Schema::Result::User');
- foreach (qw[username password email]) {
+ foreach (qw[username email]) {
is($user->$_, $user2->$_, "$_ is correct");
}
+ ok($user->check_password('pass'), 'password is correct');
$user2->password('another password');
$user2->update;
# re-read from db
$user2->discard_changes;
- is($user2->password, 'another password', 'Updated password is correct');
+ ok($user2->check_password('another password'), 'Updated password is correct');
$user_rs->delete;
}
Please sign in to comment.
Something went wrong with that request. Please try again.