There's modules that can do work for you, but if you're wanting to do something fairly simple and learn in the process, you can roll a pretty simple script. Here's a generic (and simplistic) skeleton to give you an idea.
use CGI;
my $cgi = new CGI;
my $user = $cgi->param("username");
my $pass = $cgi->param("password");
my $valid = 0;
# Assuming usernames/passwords in a delimited text file
open(IN, "passwordFile") or die(...);
while(<IN>) {
if( /^$user\:$pass$/ ) {
$valid = 1;
last;
}
}
close(IN)
if(!$valid) {
print "Sorry, you may not access this page.";
exit;
}
#set authentication
#set a cookie here using javascript
or
#add hidden fields with login info
print "<input type='hidden' name='pass' value='...'>";
print "<input type='hidden' name='user' value='...'>";
Store usernames/passwords in a file as follows:
johndoe:myPassw0rd
user2:pass2
user3:pass3
etc
You have to decide how you wish to keep users authenticated. There a number of approaches you can take. Since it sounds like you want something simple, the easiest ways may be to either set a cookie for the user or to pass around a hidden <input> field. Neither of those is very secure, but neither is a plain text password file. How worried are you about security, do you need more than that?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|