note
swkronenfeld
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.<br><br>
<code>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
</code><br><br>
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 <code><input></code> 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?
513736
513736