
CGI::Authen::Simple - Simple cookie-driven unsessioned form-based authentication

use CGI::Authen::Simple;
my $auth = CGI::Authen::Simple->new();
$auth->logged_in() || $auth->auth();
# do stuff here
# if you need it, you can access the user's credentials like so:
my $username = $auth->{'profile'}->{'username'};
# assume your account table had other attributes, like full_name char(64)
my $fullname = $auth->{'profile'}->{'full_name'};
# their password is never returned in plain text
print $auth->{'profile'}->{'password'};
# prints the MySQL hash of their password

This module provides extremely simple forms-based authentication for web applications. It has reasonable defaults set, and if your database conforms to those defaults, you can instantiate a new object with no parameters, and it will handle all the authentication and cookie settings for you.

Returns a new CGI::Authen::Simple object. Accepts a single hashref as a parameter. The hashref contains config information:
Uses cookies to determine if a user is logged in. Returns true if user is logged in. If a row is retrieved from the DB, then all the columns making up the row for that user in the accounts table will be pulled and stored as the user's profile, which is accessible as a hashref via $auth->{'profile'}.
Authenticates a user if data was posted containing a username and password pair. If authentication was unsuccessful or they did not pass a username/password pair, they are displayed a login screen. If we retrieve a row (valid username and password), then grab the rest of the columns from that table, and store them internally as the user's profile.
Note: If a login screen is displayed, the value of EXIT_ON_DISPLAY is checked. If EXIT_ON_DISPLAY is true (1), then the function will exit. This is the default behaviour. As far as I am aware, this is highly undesirable in mod_perl applications, so please be sure you've taken that into consideration. If EXIT_ON_DISPLAY is set to false, the function will not exit, and control will be returned to the calling script. In this case, please wrap your code in a surrounding:
if($auth->logged_in())
{
# do stuff here
}
code block, or else you will be displaying not only the auth screen, but anything that would be displayed by your code.

- template / CSS overrides - needs to work with any DB software (since it just takes a DBH, maybe use SQL::Abstract to generate a cross DB compatible query.

CGI::Cookie, CGI, Template

Shane Allen <opiate@gmail.com>


Copyright 2005, Shane Allen. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.