[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: perl script & password auth.



Even though you're using .htaccess, this is still doable.

It's actually pretty easy. What I'd do is something like the following:

# all of your initial CGI junk

if ($INPUT->{submit}eq "Login"){
    if ($INPUT->{password} eq "YOUR PASSWORD HERE")

        # execute your program
    } else {
        print "you're not authorized to execute this script.";
        exit(0);
    }
} else {
    # print a form that asks for a password. something like the following:
    print <<EOF;
    <form method="post" action="myfile.cgi">
    Enter the password:<input type="password" name="password"><br>
    <input type="submit" name="submit" value="Login">
    </form>
    EOF

} # end else

this way, when someone goes to your file, it sees there's no "submit" key in
the INPUT hash, so it just prints out a form. then when you login, it checks
your pass (you can also implement a username, too), and compares it to your
password in the program. if it's good, it executes your script.

that's basically what i did with my chat room, only it's got very little
hardcoding. conf files own :)

(shameless plug: http://www.daily-bull.com/chat/ )


-Adam

----- Original Message -----
From: "Andy Zobro" <ajzobro@xxxxxxx>
To: <lug-l@xxxxxxx>
Sent: Tuesday, June 25, 2002 6:49 PM
Subject: perl script & password auth.


>
> I have written a perl script that I would like only authorized persons to
> be able to execute through a cgi interface.  Has anyone done anything like
> this? if so, what do I need to do in order to accomplish this feat.
>
> - AZ
>