Skip Menu |

This queue is for tickets about the Catalyst-Plugin-Authentication-Store-Htpasswd CPAN distribution.

Report information
The Basics
Id: 16518
Status: resolved
Priority: 0/
Queue: Catalyst-Plugin-Authentication-Store-Htpasswd

People
Owner: Nobody in particular
Requestors: nigel.metheringham [...] Dev.intechnology.co.uk
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.011
Fixed in: (no value)



Subject: Unknown username causes exception
Am getting an exception if the user supplied does not exist in the htpasswd file. [Thu Dec 15 17:20:51 2005] [catalyst] [error] Caught exception "Can't call method "username" on an undefined value at /usr/local/share/perl/5.8.7/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm line 21." Looks like this is down to this in Backend.pm:- sub get_user { my ( $self, $id ) = @_; Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self, $self->file->lookup_user($id) ); } specifically $self->file->lookup_user($id) is returning undef so the user component of Catalyst::Plugin::Authentication::Store::Htpasswd::User is set to undef.
From: David Kamholz <davekam [...] pobox.com>
Subject: Re: [cpan #16518] Unknown username causes exception
Date: Thu, 15 Dec 2005 23:06:27 +0100
To: bug-Catalyst-Plugin-Authentication-Store-Htpasswd [...] rt.cpan.org
RT-Send-Cc:
Err... what were you expecting to get, exactly? Presumably, if you try to log in a user that doesn't exist in the htpasswd file, it should not succeed, and $c->user will be undef in Catalyst. Am I missing something? Dave
[guest - Thu Dec 15 12:34:03 2005]: Show quoted text
> Am getting an exception if the user supplied does not exist in the > htpasswd file. > > [Thu Dec 15 17:20:51 2005] [catalyst] [error] Caught exception "Can't > call method "username" on an undefined value at
Sounds like you're doing something like if ( $c->user->username ). What you really want to do is this: if ( $c->login( $username, $password ) ) { # user is logged in, now you can use $c->user } or... $c->login( $username, $password ); if ( $c->user_exists ) { # user is logged in, now you can use $c->user }
From: Nigel Metheringham <nigel.metheringham [...] dev.intechnology.co.uk>
[AGRUNDMA - Thu Dec 15 17:37:50 2005]: Show quoted text
> Sounds like you're doing something like if ( $c->user->username ). What > you really want to do is this: > > if ( $c->login( $username, $password ) ) { > # user is logged in, now you can use $c->user > } > > or... > > $c->login( $username, $password ); > if ( $c->user_exists ) { > # user is logged in, now you can use $c->user > }
Sorry - should have provided more context. I am experimenting based on the advent calendar examples at http://catalyst.perl.org/calendar/2005/14 The Authentication Authentication::Credential::Password Authentication::Store::Htpasswd Authorization::Roles plugins are loaded. The only function touching authentication at present is in the main app module (ie rather than a controller module):- sub dologin : Local { my ($self, $c) = @_; $c->stash->{template} = 'login.tt2'; my $user = $c->req->param("user"); my $password = $c->req->param("password"); if ($user && $password) { if ( $c->login($user, $password) ) { $c->stash->{message} = 'Login OK'; } else { # login incorrect $c->stash->{message} = 'Login incorrect'; } } else { $c->stash->{message} = 'No credentials'; } } The name had to be changed from 'login' since otherwise the $c->login loops back to here (with amusing consequences). This, on its own, causes an exception if an unknown username is entered. Thats why I considered it a bug in the auth module. [Originally mailed, then added to the web f/e when if failed to appear]
From: Nigel Metheringham <nigel.metheringham [...] dev.intechnology.co.uk>
OK, the problem is that the id method is bombing. I have fixed this by adding a check to it...
--- /usr/local/share/perl/5.8.7/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm 2005-11-27 22:21:38.000000000 +0000 +++ lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm 2005-12-16 11:40:20.000000000 +0000 @@ -18,7 +18,7 @@ sub id { my $self = shift; - return $self->user->username; + return defined($self->user) ? $self->user->username : undef; } sub supported_features {
This was fixed in the constructor instead, a long while ago, in http://dev.catalyst.perl.org/ changeset/2774