Content of the file "login.htm":

<HTML>

<HEAD>

<TITLE>LogIn</TITLE>

</HEAD>

<BODY TEXT="#000000" LINK="#0000ff" VLINK="#800080">

<FONT SIZE=5 COLOR="#ff0000"><STRONG><P ALIGN="CENTER">Log In</P></FONT></STRONG>

<P><HR></P>

 

<FORM method = "post" enctype= "multipart/form-data" action = "login.pl">

<DIR>

<B><FONT FACE="Arial" SIZE=2 COLOR="#ff0000"><P>User Name : &nbsp;</B></FONT>

<INPUT TYPE="TEXT" NAME="UserName"></P>

<B><FONT FACE="Arial" SIZE=2 COLOR="#ff0000"><P>Password : &nbsp;&nbsp;</B></FONT>

<INPUT TYPE="TEXT" NAME="Password"></P>

</DIR>

<P><HR></P>

<P ALIGN="CENTER"><INPUT TYPE="submit" VALUE="Enter"></P>

</FORM>

</BODY>

</HTML>

 

Content of the file "login.pl":

#!/usr/local/bin/perl -w

#***********************************************************

# LOGIN Input Username/Password and CHECK at the DATABASE

#***********************************************************

use CGI qw( :standard );

use diagnostics;

my $q = new CGI;

 

# READ the LogIn Data from the ENVIRONMENT VARIABLES

#................................................................

my $name = $q->param("UserName");

my $pass = $q->param("Password");

 

use DBI;

 

# SETUP the Database VARIABLES

# ......................................................................

my $database = 'ecity'; # your_database_name

my $db_user = 'ecity'; # 'your_user_name MySQL

my $db_password = '112233'; # your_password MySQL

 

my ($dbh, $sth); # database and statement handles

my (@ary); # array for rows returned by query

 

# CONNECT to the Database

#..............................................................

 

$dbh = DBI->connect("DBI:mysql:${database}:zodiac.cs.newpaltz.edu:3306",

$db_user, $db_password)

or die "Wrong Database or Username or Password\n";

 

# Send QUERY to the Database (READ data from the table "users")

#..............................................................

  

# issue query

my $query = qq{ SELECT PASSWORD FROM users WHERE USERNAME="$name" };

 

# send query

$dbh->do($query) or print "errors in SELECT from Database.";

 

$sth = $dbh->prepare( $query );

$sth->execute();

 

my @a;

 

# read results of query, then clean up

while (@ary = $sth->fetchrow_array ())

{

push(@a,@ary); # save the result as @ary will be cleaned;

}

$sth->finish();

 

$dbh->disconnect;

 

 

sub UserNotIn {

 

#-------------------------------------------------------------------#

# LogIn Failed #

#-------------------------------------------------------------------#

 

print $q->header("text/html");

 

print <<End_Err;

<HTML>

<HEAD>

<TITLE>Result</TITLE>

</HEAD>

<BODY TEXT="#000000" LINK="#0000ff" VLINK="#800080""><br>

Password Entered was NOT correct !!!

</BODY></HTML>

End_Err

 

} # End of UserNotIn

 

 

sub UserIn {

 

#-------------------------------------------------------------------#

# Link to other page #

#-------------------------------------------------------------------#

 

print $q->header("text/html");

 

print <<End_Success;

<HTML>

<HEAD>

<TITLE>Result</TITLE>

</HEAD>

<BODY TEXT="#000000" LINK="#0000ff" VLINK="#800080""><br>

You are IN <br>

Clich Here to begin <br>

</BODY></HTML>

End_Success

 

} # End of UserIn

 

 

# PRODUCE a Reply HTM file

#....................................

 

if ($pass eq $a[0])

{

UserIn();

}

else

{

UserNotIn();

}