CGI::A...Driver(3pm)
CGI::Application::Plugin::Authentication::Driver π«Ά
okay so this is the CGI::A...Driver(3pm) manual page, bestie β literally the base class for all driver classes for the CGI::Application::Plugin::Authentication plugin. If you're building a driver, the vibe is simple: provide one method that validates credentials, and the plugin handles the rest. No cap.
β¨ NAME β¨
CGI::Application::Plugin::Authentication::Driver β base module for building driver classes for CGI::Application::Plugin::Authentication.
β¨ SYNOPSIS β¨
package CGI::Application::Plugin::Authentication::Driver::MyDriver;
use base qw(CGI::Application::Plugin::Authentication::Driver);
sub verify_credentials {
my $self = shift;
my @credentials = @_;
if ( >>> Validate Credentials <<< ) {
return $credentials[0];
}
return;
}
π DESCRIPTION π
This module is the base class for every driver class in the CGI::Application::Plugin::Authentication plugin fam. Each driver class is required to provide only one method to validate the given credentials.
Normally only two credentials get passed in β username and password β but bestie, you can configure the plugin to handle any number of credentials. Like, maybe you need the user to enter a group name or domain name as well as a username and password. It's giving flexible π.
π FIELD FILTERS π
It is quite common for passwords to be stored using some form of one-way encryption. Unix crypt is the old standard in the Unix community, but MD5 or SHA1 hashes are more popular today. To simplify the validation routines, some methods are provided to help test these passwords.
When configuring a Driver β and only if the driver supports it β you can specify which fields are encoded and which method is used for the encoding by specifying a filter on the field in question.
CREDENTIALS => ['authen_username', 'authen_password'],
DRIVERS => [ 'DBI',
DSN => '...',
TABLE => 'users',
CONSTRAINTS => {
username => '__CREDENTIAL_1__',
'MD5:password' => '__CREDENTIAL_2__',
}
],
Here we are saying the password field is encoded using an MD5 hash and should be checked accordingly. Slay.
Filter options
Some of the filters may have multiple forms. For example, there are three forms of MD5 hashes: binary, base64 and hex. You can specify these extra options by using an underscore to separate it from the filter name.
'MD5_base64:password'
Chained Filters
It is possible to chain multiple filters. This can be useful if your MD5 strings are stored in hex format. Hex numbers are case insensitive, so they may be stored in either upper or lower case. To make this consistent, you can MD5 encode the password first and then upper case the results. The filters are applied from the inside out:
'uc:MD5_hex:password'
Custom Filters
If your field is encoded using a custom technique, then you can provide a custom filter function. This can be done by providing a FILTERS option that contains a hash of filter subroutines keyed by their name. You can then use the filter name on any of the fields as if it was a builtin filter.
CREDENTIALS => ['authen_username', 'authen_password'],
DRIVERS => [ 'DBI',
DSN => '...',
TABLE => 'users',
CONSTRAINTS => {
username => '__CREDENTIAL_1__',
'rot13:password' => '__CREDENTIAL_2__',
}
FILTERS => { rot13 => \&rot13_filter },
],
sub rot13_filter {
my $param = shift;
my $value = shift;
$value =~ tr/A-Za-z/N-ZA-Mn-za-m/;
return $value;
}
Please see the documentation for the driver that you are using to make sure that it supports encoded fields. iykyk π«Ά
Builtin Filters
Here is a list of the filters provided with this module:
cryptβ provided by the perlcryptfunctionMD5β requiresDigest::MD5SHA1β requiresDigest::SHA1ucβ provided by the perlucfunctionlcβ provided by the perllcfunctiontrimβ removed whitespace from the start and end of the field
πΈ METHODS πΈ
new
This is a constructor that can create a new Driver object. It requires an Authentication object as its first parameter, and any number of other parameters that will be used as options depending on which Driver object is being created. You shouldn't need to call this β the Authentication plugin takes care of creating Driver objects. main character energy, honestly.
initialize
This method will be called right after a new Driver object is created. So any startup customizations can be dealt with here. setup era β¨
options
This will return a list of options that were provided when this driver was configured by the user.
authen
This will return the underlying CGI::Application::Plugin::Authentication object. In most cases it will not be necessary to access this.
find_option
This method will search the Driver options for a specific key and return the value it finds.
verify_credentials
This method needs to be provided by the driver class. It needs to be an object method that accepts a list of credentials, and will verify that the credentials are valid, and return a username that will be used to identify this login. Usually you will just return the value of the first credential, however you are not bound to that. periodt.
filter
This method can be used to filter a field β usually password fields β using a number of standard or custom encoding techniques. See the section on Builtin Filters above to see what filters are available.
When using a custom filter, you will need to provide a FILTERS option in the configuration of the DRIVER (see the section on FIELD FILTERS above for an example). By default, if no filter is specified, it is returned as is. This means that you can run all fields through this function even if they don't have any filters, to simplify the driver code.
my $filtered = $self->filter('MD5_hex:password', 'foobar');
- or -
# custom filter
my $filtered = $self->filter('foobar:password', 'foo');
- or -
# effectively a noop
my $filtered = $self->filter('username', 'foo');
check_filtered
This method can be used to test filtered fields β usually password fields β against a number of standard or custom encoding techniques. The following encoding techniques are provided: plain, MD5, SHA1, crypt.
When using a custom encoder, you will need to provide it in the configuration of the DRIVERS (see the section on ENCODED PASSWORDS above for an example). By default, if no encoding is specified, it is assumed to be 'plain'. This means that you can run all fields through this function even if they don't have any encoding, to simplify the driver code.
my $verified = $self->check_filtered('MD5:password', 'foobar', 'OFj2IjCsPJFfMAxmQxLGPw');
- or -
# custom encoder
my $verified = $self->check_filtered('foobar:password', 'foo', 'bar');
- or -
# a field that isn't filtered (effectively just checks for equality on second and third args)
my $verified = $self->check_filtered('username', 'foobar', 'foobar');
my $verified = $self->check_filtered('plain:username', 'foobar', 'foobar');
strip_field_names
This method will take a field name (or list of names) and strip off the leading encoding type. For example, if you passed in 'MD5:password', the method would return 'password'.
my $fieldname = $self->strip_field_names('MD5:password');
π¦ SEE ALSO π¦
Go peek at CGI::Application::Plugin::Authentication and perl(1).
π AUTHOR π
Cees Hek <ceeshek@gmail.com>
π LICENCE AND COPYRIGHT π
Copyright (c) 2005, SiteSuite. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π DISCLAIMER OF WARRANTY π
okay legal bestie, this is the whole all-caps warning, and it means what it says:
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
cute sign-off: this page is from the User Contributed Perl Documentation, forperl v5.38.2, dated2024-06-29, and the manual name isCGI::A...Driver(3pm)β love u, bye π
π¦ where this page comes from
- debian trixie: libcgi-application-plugin-authentication-perl 0.25+~cs0.5-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcgi-application-plugin-authentication-perl 0.25+~cs0.5-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcgi-application-plugin-authentication-perl 0.25+~cs0.5-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms