You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ariel Manzur <hl...@freeweb.com.ar> on 2000/06/13 14:02:27 UTC
Re: Where do I put my code?
Hi.. this is very helpful.. thanks.. :-)
Now, I have one last question. Where do I put the "pachage Test::AuthAny" code?
At 09:24 13/06/2000 -0400, darren chamberlain wrote:
>> I need apache to do this: always ask for authentication, accept any
>> username/password as valid, and set an enviroment variable with the
>> password, so I can retrieve it on a CGI script later. I wrote this code:
>
>You're on the right track; put this code into it's own module, and run it.
>This should work:
>
>package Test::AuthAny;
>
>use strict;
>use Apache::Constants qw( OK AUTH_REQUIRED );
>
>sub handler {
> my $r = shift;
> my ($u,$p) = ($r->connection->user,($r->get_basic_auth_pw)[1]);
>
> if ($u && $p) {
> $r->subprocess_env(USERNAME => $u);
> $r->subprocess_env(PASSWORD => $p);
> return OK;
> } else {
> $r->note_basic_auth_failure;
> $r->log_reason("username and password don't match");
> return AUTH_REQUIRED;
> }
>}
>1;
>__END__
>
>
>Install it as a PerlAuthenHandler for /auth/ like so:
>
><Location /auth>
> # Any other directievs you might have here already ...
> AuthType Basic
> AuthName "Name of the Authentcation Realm"
> require valid-user
> PerlAuthenHandler Test::AuthAny
></Location>
>
>Now, from your CGI scripts, or SSI's, or whatever, you can grab $ENV{USERNAME}
>and $ENV{PASSWORD} and use them.
>
>> Thanks.. Bye.
>>
>> Ariel.
>
>darren
>
>--
>There are worse things in life than death. Have you ever spent an
>evening with an insurance salesman?
>-- Woody Allen