Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

RE: Getting username and password from the URL.

by jjhorner (Hermit)
on Jun 12, 2000 at 03:08 UTC ( [id://17647]=note: print w/replies, xml ) Need Help??


in reply to Getting username and password from the URL.

If you are using mod_perl, try this:

$username = $r->connection->user my($ret, $password) = $r->get_basic_auth_pw;

The $username will be the username entered when challenged, $ret will be either OK, DECLINED, SERVER_ERROR, or AUTH_REQUIRED, and $password will be the plain text password entered at the challenge. These must be used with Basic authorization type.

J. J. Horner
Linux, Perl, Apache, Stronghold, Unix
jhorner@knoxlug.org http://www.knoxlug.org/

Replies are listed 'Best First'.
RE: RE: Getting username and password from the URL.
by Punto (Scribe) on Jun 12, 2000 at 06:33 UTC
    If you are using mod_perl, try this:

    The server is running mod_perl (I can see "mod_perl" on the "server" part of the http responses), I tryed this:

    #!/usr/bin/perl print "Content type: text/html\n\n"; $username = $r->connection->user; my($ret, $password) = $r->get_basic_auth_pw; print $password;
    And I get an "Internal Server Error". Do I have to use some library or something on the script?

    Thanks!

      Yes, you'll need to get the $r object, which you don't have in your script. $r is the Apache request record.

      You should set up your script as an Apache::Registry script. Then you can get $r like this:

      my $r = Apache->request;
      To set the script up as Apache::Registry, add something like this to httpd.conf:
      <Location /perl> SetHandler perl-script PerlHandler Apache::Registry Options +ExecCGI </Location>
      This sets up the perl subroutine under the document root to run under Apache::Registry. So put your script there.

      Or, if you set up a mod_perl handler, your handler subroutine will be passed $r.

      For example, you might set up a handler thusly in your httpd.conf:

      <Location /foo> SetHandler perl-script PerlHandler My::Foo </Location>
      And then in My::Foo:
      package My::Foo; use strict; sub handler { my $r = shift; my $user = $r->connection->user; my($ret, $password) = $r->get_basic_auth_pw; $r->send_http_header; $r->print($user); $r->print($password); } 1;
      I'd recommend trying the first approach.

      While btrott's answer was right, I thought I would send you to a real world example here.

      J. J. Horner
      Linux, Perl, Apache, Stronghold, Unix
      jhorner@knoxlug.org http://www.knoxlug.org/
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://17647]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2025-05-18 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.