Anonymous Authentication

This Apache Perl module accepts an anonymous login like anonymous FTP.

Configuration Entry

 <Location /anonymous>
   AuthName Anonymous
   AuthType Basic
   PerlAuthenHandler Apache::AuthAnon
   require valid-user
   PerlSetVar Anonymous anonymous|anybody
 </Location>

Script III.4.2: Apache::AuthAnon

 package Apache::AuthAnon;
 # file: Apache/AuthAnon.pm

 use strict;
 use Apache::Constants ':common';

 my $email_pat = '\w+\@\w+\.\w+';
 my $anon_id  = "anonymous";

 sub handler {
     my $r = shift;

     my($res, $sent_pwd) = $r->get_basic_auth_pw;
     return $res if $res != OK;

     my $user = lc $r->connection->user;
     my $reason = "";

     my $check_id = $r->dir_config("Anonymous") || $anon_id;

     unless($user =~ /^$check_id$/i) {
	 $reason = "user did not enter a valid anonymous username";
     }

     unless($sent_pwd =~ /$email_pat/o) {
	 $reason = "user did not enter an email address password";
     } 

     if($reason) {
	 $r->note_basic_auth_failure;
	 $r->log_reason($reason,$r->filename);
	 return AUTH_REQUIRED;
     }

     $r->notes(AuthAnonPassword => $sent_pwd);

     return OK;
 }

 1;
http://localhost/anonymous/test_document.html
<< Previous
Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Mon Aug 17 10:49:50 EDT 1998