File Coverage

blib/lib/CGI/Application/Plugin/Authentication/Driver/HTPasswd.pm
Criterion Covered Total %
statement 20 20 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 30 30 100.0


line stmt bran cond sub pod time code
1             package CGI::Application::Plugin::Authentication::Driver::HTPasswd;
2             $CGI::Application::Plugin::Authentication::Driver::HTPasswd::VERSION = '0.23';
3 1     1   6 use strict;
  1         2  
  1         23  
4 1     1   4 use warnings;
  1         2  
  1         22  
5              
6 1     1   5 use base qw(CGI::Application::Plugin::Authentication::Driver);
  1         2  
  1         432  
7 1     1   6 use Apache::Htpasswd;
  1         1  
  1         114  
8              
9             =head1 NAME
10              
11             CGI::Application::Plugin::Authentication::Driver::HTPasswd - HTPasswd
12             Authentication driver
13              
14             =head1 SYNOPSIS
15              
16             use base qw(CGI::Application);
17             use CGI::Application::Plugin::Authentication;
18              
19             __PACKAGE__->authen->config(
20             DRIVER => ['HTPasswd', '/etc/apache/htpasswd', '/etc/apache/otherhtpasswd']
21             );
22              
23             =head1 DESCRIPTION
24              
25             This Driver allows you to authenticate against an htpasswd file. For
26             information on the format of the htpasswd file, see the documentation for the
27             Apache webserver. This driver requires that the L module is
28             installed.
29              
30              
31             =head1 METHODS
32              
33             =head2 verify_credentials
34              
35             This method will test the provided credentials against the htpasswd file(s)
36             defined in the DRIVER config.
37              
38             =cut
39              
40             sub verify_credentials {
41 11     11 1 20 my $self = shift;
42 11         24 my ( $username, $password ) = @_;
43              
44             # verify that all the options are OK
45 11         26 my @files = $self->options;
46 11 100       30 die "The HTPasswd driver requires at least one htpasswd file"
47             unless @files;
48              
49 10         28 foreach my $file (@files) {
50 16         778 my $htpasswd = Apache::Htpasswd->new(
51             { passwdFile => $file,
52             ReadOnly => 1,
53             }
54             );
55 16 100       372 return $username
56             if $htpasswd->htCheckPassword( $username, $password );
57             }
58 5         461 return;
59             }
60              
61             =head1 SEE ALSO
62              
63             L,
64             L, perl(1)
65              
66              
67             =head1 LICENCE AND COPYRIGHT
68              
69             Copyright (c) 2005, SiteSuite. All rights reserved.
70              
71             This module is free software; you can redistribute it and/or modify it under
72             the same terms as Perl itself.
73              
74              
75             =head1 DISCLAIMER OF WARRANTY
76              
77             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE
78             SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
79             STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
80             SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
81             INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
82             FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
83             PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE,
84             YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
85              
86             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
87             COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
88             SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES,
89             INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
90             OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO
91             LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
92             THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE),
93             EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
94             DAMAGES.
95              
96             =cut
97              
98             1;