Apache-AppSamurai

 view release on metacpan or  search on metacpan

lib/Apache/AppSamurai/AuthBase.pm  view on Meta::CPAN

    # Check password against the list of valid password characters
    unless ($pass =~ /^([$self->{conf}{PassChars}]+)$/) {
	$self->AddError('warn', 'Password contains invalid characters');
	return undef;
    }

    # Check for a valid password length.
    if ($plen < $self->{conf}{PassMin}) {
	$self->AddError('warn', "Password too small ($plen)");
	return undef;
    } elsif ($plen > $self->{conf}{PassMax}) {
	$self->AddError('warn', "Password too large ($plen)");
	return undef;
    }

    return $pass;
}


# Add error to the list
sub AddError {
    my $self = shift;
    if (scalar(@_) == 2) {
	push(@{$self->{errors}}, [$_[0], ref($self) . ": " . $_[1]]);
    } else {
	push(@{$self->{errors}}, [$self->{conf}{DefaultLogLevel}, ref($self) . ": " . $_[0]]);
    }
    return 1;
}

# Return an array of errors if there are any, or undef if there are not.
sub Errors {
    my $self = shift;
    if (scalar(@{$self->{errors}})) {
	return $self->{errors};
    }
    
    return undef;
}

1; # End of Apache::AppSamurai::AuthBase

__END__

=head1 NAME

Apache::AppSamurai::AuthBase - Base module for all AppSamurai authentication
                               sub modules.

=head1 SYNOPSIS

All L<Apache::AppSamurai|Apache::AppSamurai> authentication modules should
inherit from this base module.  This module is never used directly.
See L<Apache::AppSamurai|Apache::AppSamurai> for details on authentication
module config and use within AppSamurai.                

=head1 DESCRIPTION

All L<Apache::AppSamurai|Apache::AppSamurai> authentication submodules
should inherit from Auth::Base.  This module provides the a standard
framework including config, initialization, basic input validation and
filtering, error checking, and logging needed by all AppSamurai auth modules.

Auth modules must each define at least an L</Authenticator()> method to accept
the username (C<credential_0>) and the mapped credential (password) and return
0 on failure and 1 on success.  Other commonly overridden methods are
L</Configure()> which includes the setup of the C< $self->{conf} >
configuration hash, and L</Initialize()> which performs any needed
pre-authentication setup work.

=head1 METHODS

=head2 new()

Runs I<Configure()>, (passing along any arguments), which creates and
populates the C<< %{$self->{conf}} >> hash.  Then creates and sets
the C<< $self->{init} >> flag to 0, and creates and clears the
C<< @{$self->{errors}} >> array.

The instance is then returned.

Alternately, if a C<< $self->{conf}{user} >> and C<< $self->{conf}{pass} >>
exist, C<< $self->Authenticate() >> is called with those values and the result
is returned.
(Note - This behavior is not currently used by Apache::AppSamurai).

=head2 Configure()

Creates and populates the instance's configuration hash,
C<< %{$self->{conf}} >>.
Each auth module has a basic set of default configuration items from
Auth::Base, plus any additional items added in its own C<Configure()> method,
plus any configuration items passed in when C<Configure()> is called.
Arguments take precedence over defaults in the particular auth module,
and the auth module's defaults take precedence over those in Auth::Base.

See L</EXAMPLES> for an example of overriding C<Configure()> while
preserving the Auth::Base defaults.

The following keys are set in Auth::Base, and are also used by methods
in Auth::Base for input validation, logging, and other purposes.

=head3 I<UserMin>

Minimum characters in username. (Default: 3)

=head3 I<UserMax>

Maximum characters in username. (Default: 256)

=head3 I<UserChars>

Characters allowed in the username.  These are matched with a Perl regex,
and character classes like C<\w> and C<\d> are allowed. (Default:
C<< \w\d_\-\. >>)

=head3 I<UserStripWhite>

If set to 1, strips any whitespace surrounding the username.
(Default: 1)



( run in 1.195 second using v1.01-cache-2.11-cpan-df04353d9ac )