NAME
CGI::Session::Auth - Authenticated sessions for CGI scripts
ABSTRACT
CGI::Session::Auth is a Perl class that provides the necessary functions for authentication in CGI scripts. It uses CGI::Session for session management and supports several backends for user and group data storage.
SYNOPSIS
use CGI;
use CGI::Session;
use CGI::Session::Auth;
# CGI object for headers, cookies, etc.
my $cgi = new CGI;
# CGI::Session object for session handling
my $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'});
# CGI::Session::Auth object for authentication
my $auth = new CGI::Session::Auth({ CGI => $cgi, Session => $session });
$auth->authenticate();
# check if visitor has already logged in
if ($auth->loggedIn) {
showSecretPage;
}
else {
showLoginPage;
}
DESCRIPTION
CGI::Session::Auth offers an alternative to HTTP authentication. Its goal is to integrate the authentication process into the web application as seamless as possible while keeping the programming interface simple.
Users can authenticate themselves by entering their user name and password into a login form. This is the most common way of authenticating a web site visitor.
Alternatively, a user can automatically be authenticated by his IP address. This is useful when authorized users can't be bothered to log in manually but can be identified by a range of fixed IP addresses.
CGI::Session::Auth manages a profile for every user account, containing his user name, his password and his user id. The user profile may contain additional fields for arbitrary data.
The CGI::Session::Auth class itself is only an abstract base class with no real storage backend (only the user 'guest' with password 'guest' may log in). See its subclasses for real implementations.
METHODS
new(\%parameters)
This is the class constructor. The hash referenced by \%parameters
must contain the following key/value pairs:
- CGI
-
A reference to an CGI or CGI::Simple object.
- Session
-
A reference to an CGI::Session object.
Additionally, the following optional parameters are possible:
- IPAuth
-
Try to authenticate the visitor by his IP address. (Default: 0)
- LoginVarPrefix
-
A string the names of the login form fields begin with. (Default. 'log_')
- Log
-
Set to 1 to enable logging. CGI::Session::Auth expects an initialized Log::Log4perl module and gets its logger object calling Log::Log4perl->get_logger('CGI::Session::Auth').
authenticate()
This method does the actual authentication. It fetches session information to determine the authentication status of the current visitor and further checks if form variables from a proceeding login form have been set and eventually performs a login attempt. If authentication succeeded neither by session data nor login information, and the parameter IPAuth
is set to a true value, it tries to authenticate the visitor by his IP address.
sessionCookie()
For the session to be persistent across page requests, its session ID has to be stored in a cookie. This method returns the correct cookie (as generated by CGI::cookie()), but it remains the duty of the CGI application to send it.
loggedIn()
Returns a boolean value representing the current visitors authentication status.
logout()
Discards the current visitors authentication status.
hasUsername($username)
Checks if a certain user is logged in.
isGroupMember($groupname)
Checks if the current user is a member of a certain user group.
profile($key [, $value])
Returns the user profile field identified by $key
. If $value
is given, it will be stored in the respective profile field first.
BUGS
This software is still in alpha status. It's meant only to show its basic functionality. Features and interface are subject to change. If you want to use CGI::Session::Auth in a production environment, please wait for version 1.0.
Assistance in the development of this modules is encouraged and greatly appreciated! Please contact me at jl@teamlinux.de!
TODO
Don't get me started...
SEE ALSO
For further information (mailing lists, FAQ, etc.), see the module web site: http://geewiz.teamlinux.de/projects/perl/cgi-session-auth
AUTHOR
Jochen Lillich, <jl@teamlinux.de>
THANKS
These people have helped in the development of this module:
COPYRIGHT AND LICENSE
Copyright (c) 2003 by Jochen Lillich
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.