Hi I am trying to write a simplie login perl script all is working apart from the final if statement. if the username and password match the data stored in the txt file $auth returns true which works then a second if checks if £name is != to "admin" if true should be directed to order page if false should go to admin page but when I run it, if the username & password are correct it always goes to the admin page regardless of the username being != to "admin" would really appreciate some help here as I really cant see why have even put a print"$name"; just to check what its value is and its not "admin"

#!"\xampplite\perl\bin\perl.exe"
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
print "Content-type:text/html\n\n";
$auth = 0;
$name = param('username');
$pass =  param('password');
open(LOGDATA,"login.txt") or dienice("Couldn't open Data File for reading: $!\n");
#set a shared lock
flock(LOGDATA,0);
#then seek the beginning of the file
seek(LOGDATA,0,0);
@raw_data = <LOGDATA>;
close(LOGDATA);
print "<html><head><title>results</title></head>\n";
print "<body>\n";
foreach $line(@raw_data)
{
	chomp ($line);
        ($user, $word) = split(",",$line);

        if ($user == $name && $pass == $word)
        {
               $auth = 1;

        }

}
if ($auth == 1)
{
	if ($name != "admin")
        {
                $usermenu = "AssiP1/order.htm";
        }
        else
        {
        	$usermenu =  "AssiP1/admin1.htm";
        }
}
else
{
	$usermenu = "AssiP1/loginfail.htm";
}

print "<html><head><title>results</title></head>\n";
print "<meta http-equiv=\"Refresh\" content=\"5;URL=//localhost/$usermenu\">\n";
print "<body>\n";
print "$name";
print "<body>\n";

sub dienice
{
        my($msg) = @_;
        print "<h2>Error</h2>\n";
        print $msg;
        exit;
}

Again any help would be great

Thanks

Niall

Recommended Answers

All 3 Replies

Hi Nail,

You are using a check that works only on digits/numbers.
Try and use this.

if ($auth ne "Admin"){
 print "foo";

}

This should work ok?

Have fun ;)

Thanks richieking works fine now saved me a big headache, need to read up now why it works but thanks for pointing me in the right direction been doing stuff in vb and java where that would of normaly worked again thanks for the reply N

perl is for nuts!
got so many little tricks. ;)

anyway your code looks very clean ;)

mmm. your appreciation sir.....


;)

mark your query as closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.