Author: spadkins
Date: Thu Feb  5 14:56:10 2009
New Revision: 12475

Added:
   p5ee/trunk/App-Repository/lib/App/Authentication/
   p5ee/trunk/App-Repository/lib/App/Authentication/Repository.pm

Log:
new

Added: p5ee/trunk/App-Repository/lib/App/Authentication/Repository.pm
==============================================================================
--- (empty file)
+++ p5ee/trunk/App-Repository/lib/App/Authentication/Repository.pm      Thu Feb 
 5 14:56:10 2009
@@ -0,0 +1,99 @@
+
+#############################################################################
+## $Id: Repository.pm 9817 2007-07-30 22:46:19Z spadkins $
+#############################################################################
+
+package App::Authentication::Repository;
+$VERSION = (q$Revision: 9817 $ =~ /(\d[\d\.]*)/)[0];  # VERSION numbers 
generated by svn
+
+use App;
+use App::Authentication;
+...@isa = ( "App::Authentication" );
+
+use strict;
+
+=head1 NAME
+
+App::Authentication::Repository - authentication against a user table in a 
database or other Repository
+
+=head1 SYNOPSIS
+
+    use App;
+
+    $context = App->context();
+    $authentication = $context->service("Authentication");  # or ...
+    $authentication = $context->authentication();
+
+    if ($authentication->validate_password($username, $password)) {
+       ...
+    }
+
+=head1 DESCRIPTION
+
+An App::Authentication::Repository service is a means by which a user may be 
authenticated
+using a user table in a database or other Repository.
+
+=cut
+
+#############################################################################
+# PUBLIC METHODS
+#############################################################################
+
+=head1 Public Methods:
+
+=cut
+
+#############################################################################
+# validate_password()
+#############################################################################
+
+=head2 validate_password()
+
+    * Signature: $username = $auth->validate_password();
+    * Param:     void
+    * Return:    $username        string
+    * Throws:    App::Exception::Authentication
+    * Since:     0.01
+
+    Sample Usage:
+
+    $username = $auth->validate_password();
+
+=cut
+
+sub validate_password {
+    &App::sub_entry if ($App::trace);
+    my ($self, $username, $password) = @_;
+    my $valid = 0;
+
+    my $context         = $self->{context};
+    my $options         = $context->{options};
+    my $rep_name        = $self->{repository};
+    my $table           = $self->{table} || "usr";
+    my $username_column = $self->{username_column} || "username";
+    my $password_column = $self->{password_column} || "password";
+
+    my $db = $context->repository($rep_name);
+    my $pword = $db->get($table, { "$username_column.eq" => $username }, 
$password_column);
+    if ($pword) {
+        my $crypt = crypt($password, $pword);
+        $valid = ($pword eq $crypt) ? 1 : 0;
+    }
+    &App::sub_exit($valid) if ($App::trace);
+    return($valid);
+}
+
+=head1 ACKNOWLEDGEMENTS
+
+ * Author:  Stephen Adkins <[email protected]>
+ * License: This is free software. It is licensed under the same terms as Perl 
itself.
+
+=head1 SEE ALSO
+
+L<C<App::Context>|App::Context>,
+L<C<App::Service>|App::Service>
+
+=cut
+
+1;
+

Reply via email to