#!/usr/bin/perl -w

require "parseform.lib";

 

&Parse_Form;

 

# The key of the reply parameter. This is a constant.

my $ResultKey="Result";

 

# reply codes. They are constants.

my $REPLY_Success   = "Success";

my $REPLY_NotFound  = "UserNotFound";

my $REPLY_WrongPass = "WrongPassword";

my $REPLY_Error     = "Error";

 

# parameters passed from CGI call.

#

my $username = $formdata{'user'};

my $password = $formdata{'pass'};

my $cookie   = $formdata{'cookie'};

# a dummy user to test the code.

# It looks like as if this is the only user in the database.

my $dummyuser = "dummy";

my $dummypass = "secret";

 

# This is required by most web servers.

print "Content-type:text/plain\n\n";

 

# user name is required.

if ( length($username) == 0 )

{

    print "$ResultKey=$REPLY_Error";

    print "\n";

    print "#empty user name.\n";

    exit 2;

}

 

if ( length($password) == 0 )

{

# password empty. You may take some action here.

}

 

if ( length($cookie) == 0 )

{

# cookie is required when authentication is done by cookie.

}

 

 

# Here is the code to connect to database and execute authentication

# based on username, password or cookie.

#if DataBase authentication failed.

#{

#    print "$ResultKey=$REPLY_Error";

#    print "\n";

#    print "#empty user name.\n";

#    return( 1 );

#}

 

 

# use the dummy user for testing.

# assuming case sensitive user names.

if ( $username eq $dummyuser )

{

# check password.

    if ( $password eq $dummypass )

    {

print "$ResultKey=$REPLY_Success";

print "\n";

# extra properties you may send back to ParaChat Server.

# see http://www.parachat.com/documentation/570/help/parachat/userconf.html

#print "pchatd.max_idle_time=3600\n";

exit 0;

    }

    else

    {

print "$ResultKey=$REPLY_WrongPass";

print "\n";

exit 0;

    }

}

 

# this user name is not in database. not a member.

 

print "$ResultKey=$REPLY_NotFound";

print "\n";

exit 0;