Another option is to create your own htauth style thing. However, I think it requires a recompile of stock Apache. There is a -D option that allows you to let HT Authentication tokens be passed through in the the $ENV{HTTP_AUTHORIZATION} variable. Some may discourage this as it opens the submitted username and password up for viewing inside the script, but it is no less secure than what you were doing with cookies. The benefit of this is that you don't have to do mod_perl (you can, we have scripts to use it and some that don't that use the same login system).

package MyAuth; sub Authorize { $ENV{HTTP_AUTHORIZATION}=~/^Basic (.*)/i ){ my $up = $1 || ''; my ($user,$pass)=split(/:/,BASE64_DECODE( $up ),2); if( db_query($user,$pass) ){ $ENV{REMOTE_USER} = $user; return "success"; }else{ print "Status: 401 Authorization Failed\r\n"; print "WWW-Authenticate: Basic realm=\"whatever\"\r\n"; print "Content-type: text/html\r\n\r\n"; print "Content to be displayed on a canceled login."; exit; } }

Then in your cgi put the following...

#!/usr/bin/perl use MyAuth; MyAuth::Authorize; # below this line I am authorized # do whatever else

You can even write a hybrid that does cookies if they have them, and htauth if they don't (we have a hybrid system that does just that).

my @a=qw(random brilliant braindead); print $a[rand(@a)];


In reply to Re: Integrating Script with .htaccess by Rhandom
in thread Integrating Script with .htaccess by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.