CGI::Session::Auth - Authenticated sessions for CGI scripts
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.
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; }
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.
This is the class constructor. The hash referenced by \%parameters must contain the following key/value pairs:
\%parameters
A reference to an CGI or CGI::Simple object.
A reference to an CGI::Session object.
Additionally, the following optional parameters are possible:
Try to authenticate the visitor by his IP address. (Default: 0)
A string the names of the login form fields begin with. (Default. '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').
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.
IPAuth
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.
Returns a boolean value representing the current visitors authentication status.
Discards the current visitors authentication status.
Checks if a certain user is logged in.
Checks if the current user is a member of a certain user group.
Returns the user profile field identified by $key. If $value is given, it will be stored in the respective profile field first.
$key
$value
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!
Don't get me started...
CGI::Session
For further information (mailing lists, FAQ, etc.), see the module web site: http://geewiz.teamlinux.de/projects/perl/cgi-session-auth
Jochen Lillich, <jl@teamlinux.de>
These people have helped in the development of this module:
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.
To install CGI::Session::Auth, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Session::Auth
CPAN shell
perl -MCPAN -e shell install CGI::Session::Auth
For more information on module installation, please visit the detailed CPAN module installation guide.