PDA

View Full Version : User Verifiacation


Yakisoba
02-23-2005, 05:17 AM
Hi All,

I am fairly new to the CGI world, however I have spent the past couple of weeks studying CGI and Perl intensly through internet tutorials and the O`Reilly Programming Perl textbook.

Currently I am trying to develop a CGI program that will allow a user to logon to a website if there username is found in a pre-defined list.

I have been able to create a small program that will verify a single value (stored in a variable), but I dont know how to make a program that will check though multiple values.
Im not worried about security or practicality of the program right now, this will just help me get a greater understanding on how CGI works.
For this example I would have the user enter a UserName into a html textbox...once the "submit" button is clicked the CGI program will take that value and check it against a list (array/hash) that is contained in a notepad/excel document (Im still not entirely sure this is possible). If found (true) the user will be directed to a LoginOK.html page in not found (flase) they will be shown a LoginNoGood.html page. Nothing fancy.

I can envision what I need to do next, but I cant seem to get anything to work. If anyone could provide an example it would be greatly appreciated.

Thanks

andyede
02-23-2005, 10:09 AM
off the top of my head, not tested


#!/usr/bin/perl
use strict;
use CGI ':standard';

my$loginName = param('loginName');

open (FILE, 'loginData.txt') or die('Could not open file');
my@loginData = <FILE>;
close (FILE);

foreach my$login (@loginData)
{
if ($loginName eq $login)
{
print redirect('loginOK.html')
}
}

print redirect('loginNoGood.html');

mlseim
02-23-2005, 04:29 PM
and right before this line,
print redirect('loginOK.html')

you should set a cookie ...
that way, they are always logged in
until they log out or close the browser.

Search on Google for: perl cookie tutorial

oh, and you might need to either
make the URL relative '../loginOK.html'
or absolute 'http://www.mysite.com/loginOK.html'

Whenever I forget a Perl command, or need to
see an example, I go to Google and enter
"Perl" as the first word, then what I'm looking
for, example: Perl array sorting
or: Perl order of operations


.never fails :thumbsup:

Yakisoba
02-24-2005, 05:39 AM
Excellent!

Thank you both for your input...I figured it was going to be pretty basic. The code you provided was perfect, all I needed to do was add the chop function. My code was similar except I was missing the param function and my for each loop was a little messed up. I will attempt to issue users a cookie next. I will also begin tinkering with .htaccess and .htpass.

Thanks again.

andyede
02-24-2005, 08:35 AM
the param and redirect functions are both from the CGI module. read up on that if you havn't already its very usful. It also has limited cookie handling abilities which have always been more than i've ever needed