new confirmation_code role
wreis [Wed, 29 Oct 2008 23:27:53 +0000 (23:27 +0000)]
lib/Reaction/InterfaceModel/Action/User/Role/ConfirmationCodeSupport.pm [deleted file]
lib/Reaction/InterfaceModel/Object/User/Role/ConfirmationCodeSupport.pm [new file with mode: 0644]

diff --git a/lib/Reaction/InterfaceModel/Action/User/Role/ConfirmationCodeSupport.pm b/lib/Reaction/InterfaceModel/Action/User/Role/ConfirmationCodeSupport.pm
deleted file mode 100644 (file)
index 1b85d26..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-package Reaction::InterfaceModel::Action::User::Role::ConfirmationCodeSupport;
-
-use Reaction::Role;
-use Digest::MD5;
-
-use namespace::clean -except => [ qw(meta) ];
-
-
-#requires qw/target_model ctx/;
-sub generate_confirmation_code {
-  my $self = shift;
-  my $ident = $self->target_model->identity_string.
-    $self->target_model->password;
-  my $secret = $self->ctx->config->{confirmation_code_secret};
-  die "Application config does not define confirmation_code_secret"
-    unless $secret;
-  return Digest::MD5::md5_hex($secret.$ident);
-};
-
-
-
-1;
-
-=head1 NAME
-
-Reaction::InterfaceModel::Action::User::Role::ConfirmationCodeSupport
-
-=head1 DESCRIPTION
-
-=head2 generate_confirmation_code
-
-=head2 meta
-
-Need to define confirmation_code_secret in application config.
-
-=head1 AUTHORS
-
-See L<Reaction::Class> for authors.
-
-=head1 LICENSE
-
-See L<Reaction::Class> for the license.
-
-=cut
diff --git a/lib/Reaction/InterfaceModel/Object/User/Role/ConfirmationCodeSupport.pm b/lib/Reaction/InterfaceModel/Object/User/Role/ConfirmationCodeSupport.pm
new file mode 100644 (file)
index 0000000..bf79eef
--- /dev/null
@@ -0,0 +1,17 @@
+package Reaction::InterfaceModel::Action::User::Role::ConfirmationCodeSupport;
+
+use Reaction::Role;
+use Crypt::Eksblowfish::Bcrypt ();
+use namespace::clean -except => [ qw(meta) ];
+
+sub generate_confirmation_code {
+    my $self = shift;
+    my $salt = join(q{}, map { chr(int(rand(256))) } 1 .. 16);
+    $salt = Crypt::Eksblowfish::Bcrypt::en_base64( $salt );
+    my $settings_base = join(q{},'$2','a','$',sprintf("%02i", 8), '$');
+    return Crypt::Eksblowfish::Bcrypt::bcrypt(
+        $self->identity_string, $settings_base . $salt
+    );
+}
+
+1;
\ No newline at end of file