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?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.