use strict;
use warnings;
-use Apache::Htpasswd;
+use Authen::Htpasswd;
use Catalyst::Plugin::Authentication::Store::Htpasswd::User;
BEGIN { __PACKAGE__->mk_accessors(qw/file/) }
sub new {
- my ( $class, $file, @extra) = @_;
+ my ( $class, $file, %extra ) = @_;
- bless { file => ( ref($file) ? $file : Apache::Htpasswd->new($file, @extra) ) },
- $class;
+ bless { file => ( ref $file ? $file : Authen::Htpasswd->new($file, \%extra) ) }, $class;
}
sub get_user {
my ( $self, $id ) = @_;
- Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $id,
- $self->file );
+ Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self->file->lookup_user($id) );
}
sub user_supports {
use strict;
use warnings;
-BEGIN { __PACKAGE__->mk_accessors(qw/file name/) }
+BEGIN { __PACKAGE__->mk_accessors(qw/user/) }
sub new {
- my ( $class, $name, $file ) = @_;
+ my ( $class, $user ) = @_;
- bless {
- name => $name,
- file => $file,
- }, $class;
+ bless { user => $user }, $class;
}
sub supported_features {
sub check_password {
my ( $self, $password ) = @_;
- return $self->file->htCheckPassword( $self->name, $password );
+ return $self->user->check_password( $password );
}
sub roles {
my $self = shift;
- split( ",", $self->info_string );
-}
-
-sub info_string {
- my $self = shift;
- $self->file->fetchInfo( $self->name );
+ split( ",", $self->user->extra_info );
}
__PACKAGE__;
(undef, my $tmp) = tempfile();
-my $passwd = Apache::Htpasswd->new({ passwdFile => "$tmp" });
+my $passwd = Authen::Htpasswd->new($tmp);
-$passwd->htpasswd("user", "s3cr3t");
+$passwd->add_user("user", "s3cr3t");
can_ok($m, "new");
isa_ok(my $o = $m->new( $passwd ), $m);
can_ok($m, "file");
-isa_ok( $o->file, "Apache::Htpasswd");
+isa_ok( $o->file, "Authen::Htpasswd");
can_ok( $m, "user_supports");
(undef, my $tmp) = tempfile();
-my $passwd = Apache::Htpasswd->new({ passwdFile => "$tmp", UseMD5 => 1 });
+my $passwd = Authen::Htpasswd->new($tmp, { encrypt_hash => 'md5' });
-$passwd->htpasswd("user", "s3cr3t");
+$passwd->add_user("user", "s3cr3t");
can_ok($m, "new");
isa_ok(my $o = $m->new( $passwd ), $m);
can_ok($m, "file");
-isa_ok( $o->file, "Apache::Htpasswd");
+isa_ok( $o->file, "Authen::Htpasswd");
can_ok( $m, "user_supports");