3 package Catalyst::Authentication::Store::Htpasswd;
4 use base qw/Class::Accessor::Fast/;
9 use Catalyst::Authentication::Store::Htpasswd::User;
10 use Scalar::Util qw/blessed/;
12 our $VERSION = '1.003';
14 BEGIN { __PACKAGE__->mk_accessors(qw/file user_field user_class/) }
17 my ($class, $config, $app, $realm) = @_;
19 my $file = delete $config->{file};
21 my $filename = ($file =~ m|^/|) ? $file : $app->path_to($file)->stringify;
22 die("Cannot find htpasswd file: $filename\n") unless (-r $filename);
23 $file = Authen::Htpasswd->new($filename);
25 $config->{file} = $file;
26 $config->{user_class} ||= __PACKAGE__ . '::User';
27 $config->{user_field} ||= 'username';
29 bless { %$config }, $class;
33 my ($self, $authinfo, $c) = @_;
34 my $htpasswd_user = $self->file->lookup_user($authinfo->{$self->user_field});
35 $self->user_class->new( $self, $htpasswd_user );
41 # this can work as a class method, but in that case you can't have
43 ref($self) ? $self->user_class->supports(@_)
44 : Catalyst::Authentication::Store::Htpasswd::User->supports(@_);
48 my ( $self, $c, $id ) = @_;
49 $self->find_user( { username => $id } );
60 Catalyst::Authentication::Store::Htpasswd - Authen::Htpasswd based
61 user storage/authentication.
71 default_realm => 'test',
76 password_field => 'password',
77 password_type => 'self_check',
89 my ( $self, $c ) = @_;
91 $c->authenticate({ username => $c->req->param("login"), password => $c->req->param("password") });
96 This plugin uses L<Authen::Htpasswd> to let your application use C<<.htpasswd>>
97 files for it's authentication storage.
103 Simple constructor, dies if the htpassword file can't be found
107 Looks up the user, and returns a Catalyst::Authentication::Store::Htpasswd::User object.
111 Delegates to L<Catalyst::Authentication::Store::Htpasswd::User->user_supports|Catalyst::Authentication::Store::Htpasswd::User#user_supports>
115 Delegates the user lookup to C<< find_user >>
121 The path to the htpasswd file. If the path starts with a slash, then it is assumed to be a fully
122 qualified path, otherwise the path is fed through C<< $c->path_to >> and so normalised to the
125 Alternatively, it is possible to pass in an L<Authen::Htpasswd> object here, and this will be
126 used as the htpasswd file.
130 Change the user class which this store returns. Defaults to L<Catalyst::Authentication::Store::Htpasswd::User>.
131 This can be used to add additional functionality to the user class by sub-classing it, but will not normally be
136 Change the field that the username is found in in the information passed into the call to C<< $c->authenticate() >>.
138 This defaults to I< username >, and generally you should be able to use the module as shown in the synopsis, however
139 if you need a different field name then this setting can change the default.
143 __PACKAGE__->config( authentication => { realms => { test => {
146 user_field => 'email_address',
150 $c->authenticate({ email_address => $c->req->param("email"), password => $c->req->param("password") });
154 Yuval Kogman C<<nothingmuch@woobling.org>>
156 David Kamholz C<<dkamholz@cpan.org>>
158 Tomas Doran C<<bobtfish@bobtfish.net>>
164 =head1 COPYRIGHT & LICENSE
166 Copyright (c) 2005-2008 the aforementioned authors. All rights
167 reserved. This program is free software; you can redistribute
168 it and/or modify it under the same terms as Perl itself.