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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|