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

use strict;
use Apache::Constants qw(: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;

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

    $reason = "user did not enter an email address password"
	unless $sent_pwd =~ /^$email_pat$/o;

    if($reason) {
	$r->note_basic_auth_failure;
	$r->log_reason($reason,$r->filename);
	return AUTH_REQUIRED;
    }
    
    $r->notes(AuthAnonPassword => $sent_pwd);
    
    return OK;
}

1;
__END__
