PDA

View Full Version : User authentification in Perl?



Stefan Krueger
07-05-2002, 11:26 AM
Are there any samples for user authentification except the ASP sample in the docs? Something in Perl for instance?
I don't need the actual authentification process, just a template that handles the communication (receiving parameters and returning success or failure).

Sunny's
07-05-2002, 02:51 PM
I am not a PERL guru, here is a sample PERL script which

1) Recieve serialnum as CGI param
2) Checks serialnum in a flat file database (subscribe.dat)
3) syntax of subscribe.dat is simple
SerialNum, PAID or UNPAID
4) Based on serialnum, appropiate response is sent to Update Service
5) Each query is logged for future records.

Here is sample subscribe.dat
1111,PAID
2222,UNPAID

Here is PERL script

#!/usr/local/bin/perl
use CGI qw(:standard);
use CGI qw/:standard :html3/;

print ("Content-Type: text/html\n\n");
ReadUserInputs ();
CheckUsersValidity ();
AddUserInputsToDB ();

sub CheckUsersValidity
{
open (CUSTOMERDB, "<subscribe.dat");

while ($dbrow=<CUSTOMERDB>)
{
@dbcol = split (/,/, $dbrow);

if ($serialnum eq $dbcol[0])
{
if ($dbcol[1] eq "PAID\n")
{
print("OK");
return;
}
else
{
print("FAILED");
print("Your Subscription is : UNPAID, please contact <a href=http://www.isv.com/subscribe>ISV</a>");
return;
}
}
}
close (CUSTOMERDB);
print("FAILED");
print("Your Serial Number is not present in our database, please contact <a href=http://www.isv.com/subscribe>ISV</a>");
}

sub ReadUserInputs
{
$serialnum=param('serialnum');
}

sub AddUserInputsToDB()
{
open (CUSTOMERDB, ">>queries.dat");
select (CUSTOMERDB);
print ("$serialnum\n");
close(CUSTOMERDB);
}

Stefan Krueger
07-06-2002, 03:57 AM
Thanks a lot.