There are many ways to do what you want, one is
#!/usr/bin/perl
use CGI qw(:standard);
use strict;
use warnings;
my $var_username = param( "USERNAME" );
my $var_password = param( "PASSWORD" );
my $url="http://host.redirectdomain.com:9999/";
my $t=1; # time until redirect activates
print "Content-Type: text/html; charset=utf-8\n\n";
open ( FILE, "/tmp/password.txt" ) || die "The file could not be opene
+d";
my $didmsg=0;
while ( my $line = <FILE> )
{
chomp $line;
( my $username, my $password ) = split( ",", $line );
if ( ( $var_username eq $username ) && ( $var_password eq $password
+ ) ) {
print "$var_username, $var_password <br>"; # I will remove this in
+real world
print "Permission has been granted <br>";
print "<META HTTP-EQUIV=refresh CONTENT=\"$t;URL=$url\">\n";
$didmsg=1;
last;
}
elsif ( ( $var_username eq $username ) && ( $var_password ne $passw
+ord ) ) {
print "$var_username, $var_password <br>"; # I will remove this in
+real world
print "You entered an invalid password. <br>";
print "Access has been denied. <br>";
$didmsg=1;
last;
}
}
close( FILE );
unless($didmsg) {
print "$var_username, $var_password <br>"; # I will remove this in
+real world
print "You entered an invalid username. <br>";
print "Access has been denied. <br>";
}
Notice the use of the $didmsg flag, and "last" to terminate the read loop early