Apache-Authen-Generic
view release on metacpan or search on metacpan
# cgi script
use Apache::Authen::Generic;
my $auth_obj = Apache::Authen::Generic->new;
if (&check_login($user, $pwd)) {
my $cookie = $auth_obj->($data, $key);
print "Set-Cookie: $cookie\n";
print "Location: $redirect_url\n";
print "\n";
} else {
&handle_invalid_password()
}
# Efforts have been made to make this module work under Apache
# 1.3.* and mod_perl 1.0, but it has only been tested under
# Apache 2.0.* and mod_perl 2.0.
=head1 DESCRIPTION
=head2 Variables to set in the Apache configuration file
# cgi script
use Apache::Authen::Generic;
my $auth_obj = Apache::Authen::Generic->new;
if (&check_login($user, $pwd)) {
my $cookie = $auth_obj->($data, $key);
print "Set-Cookie: $cookie\n";
print "Location: $redirect_url\n";
print "\n";
} else {
&handle_invalid_password()
}
# Efforts have been made to make this module work under Apache
# 1.3.* and mod_perl 1.0, but it has only been tested under
# Apache 2.0.* and mod_perl 2.0.
DESCRIPTION
Variables to set in the Apache configuration file
The following are variables to be set in the Apache
configuration file with the PerlSetVar directive.
README.examples view on Meta::CPAN
Example scripts are in the example subdirectory.
* login_form.cgi - a simple login page
* login.cgi - a login script that verifies the username and passwords
are correct and then sets the appropriate cookie using the
Apache::Authen::Generic module.
examples/login.cgi view on Meta::CPAN
&Carp::cluck(); exit 0 };
use CGI::Utils;
use Apache::Authen::Generic;
my $cgi = CGI::Utils->new;
$cgi->parse;
my $fields = $cgi->vars;
my $username = $$fields{username};
my $password = $$fields{password};
my $ref_url = $$fields{ref_url};
if ($username eq 'test' and $password eq 'pwd') {
my $key = q{abcdefghijklmnopqrstuvwxyz012346};
my $auth = Apache::Authen::Generic->new;
my $cookie = $auth->generateAuthCookie({ test_var1 => 1, auth_level => 8 },
$key, {}, 'test_cookie');
if ($ref_url =~ m{^/}) {
$ref_url = $cgi->getSelfRefHostUrl . $ref_url;
}
print "Set-Cookie: $cookie\n";
print "Location: $ref_url\n\n";
exit 0;
examples/login_form.cgi view on Meta::CPAN
print "</pre>\n";
my $msg = $$fields{msg};
if (defined($msg)) {
print qq{<p><font color="#ff0000">$msg</font></p>};
}
my $ref_dir = $cgi->getSelfRefUrlDir;
my $form = qq{<form action="$ref_dir/login.cgi" method="POST">\n};
$form .= qq{<input type="hidden" name="ref_url" value="$$fields{ref_url}" />\n};
$form .= qq{<input type="text" name="username" /><br />\n};
$form .= qq{<input type="password" name="password" /><br />\n};
$form .= qq{<input type="submit" name="submit" value="Submit" />\n};
$form .= qq{</form>\n};
print $form;
}
exit 0;
###############################################################################
# Subroutines
( run in 1.164 second using v1.01-cache-2.11-cpan-49f99fa48dc )