Authen...Adapter(3pm)
π NAME π
Authen::Simple::Adapter β it's the adapter class for implementations, bestie. That's the whole vibe. π
β¨ SYNOPSIS β¨
Here's how you'd build your own lil adapter, like an Authenticate::Simple::Larry:
package Authenticate::Simple::Larry;
use strict;
use base 'Authen::Simple::Adapter';
__PACKAGE__->options({
secret => {
type => Params::Validate::SCALAR,
default => 'wall',
optional => 1
}
});
sub check {
my ( $self, $username, $password ) = @_;
if ( $username eq 'larry' && $password eq $self->secret ) {
$self->log->debug( qq/Successfully authenticated user '$username'./ )
if $self->log;
return 1;
}
$self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ )
if $self->log;
return 0;
}
1;
see how clean that is?? immaculate. π¦
πΈ DESCRIPTION πΈ
Adapter class for implementations. That's it, that's the description, she's brief and she knows it. π
π METHODS π
new ( %parameters )β the constructor, babes. If you overload it, this method should take a hash of parameters. The following options should be valid:cache ( $ )β any object that supports"get","set". Only successful authentications are cached, so like, don't expect your fails to be remembered, they're not invited back. π
cache => Cache::FastMmap->new
callback ( \& )β a subref that gets called with two scalar references, username and password. The returns are doing the talking here, so read carefully:
callback = sub {
my ( $username, $password ) = @_;
if ( length($$password) < 6 ) {
return 0; # abort, invalid credintials
}
if ( $$password eq 'secret' ) {
return 1; # abort, successful authentication
}
return; # proceed;
}
log ( $ )β any object that supports"debug","info","error"and"warn". Give it whatever logger you've got lying around:
log => Log::Log4perl->get_logger('Authen::Simple')
log => $r->log
log => $r->server->log
init ( \%parameters )β this one gets called after construction. It should assign parameters and return the instance. Super straightforward, no drama:
sub init {
my ( $self, $parameters ) = @_;
# mock with parameters
return $self->SUPER::init($parameters);
}
authenticate ( $username, $password )β the end user method, the main character fr. It applies callback, checks cache, and calls"check"β unless it got aborted by the callback or it hit a cache hit. β¨check ( $username, $password )β must be implemented in the subclass (yes, must, no skipping π ). It should return true on success and false on failure. That's the whole job.check_password( $password, $encrypted )β okay so the source page gives this one no description at all. She's just there. Mysterious. Iconic. πoptions ( \%options )β must be set in the subclass, and it should be a valid Params::Validate specification. Accessors for options will be created unless they're already defined in the subclass. Also it's giving full example energy:
__PACKAGE__->options({
host => {
type => Params::Validate::SCALAR,
optional => 0
},
port => {
type => Params::Validate::SCALAR,
default => 80,
optional => 1
}
});
π¦ SEE ALSO π¦
Go read these too, bestie, they're all connected:
Authen::SimpleAuthen::Simple::PasswordParams::Validate
π AUTHOR π
Christian Hansen "chansen@cpan.org" β thank you for your service, king. π
π COPYRIGHT π
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. slay, legally. π
friendly reminder that this page is from User Contributed Perl Documentation, and the footer says it's perl v5.32.0, dated 2021-01-02. okay bye ily, go write that subclass πβ¨π«Ά
π¦ where this page comes from
- debian bookworm: libauthen-simple-perl 0.5-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libauthen-simple-perl 0.5-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libauthen-simple-perl 0.5-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libauthen-simple-perl 0.5-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms