Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: with CGI, How to have multiple usernames and passwords from a txt file (password.txt) file

by huck (Prior)
on Sep 26, 2018 at 05:42 UTC ( [id://1223032]=note: print w/replies, xml ) Need Help??


in reply to with CGI, How to have multiple usernames and passwords from a txt file (password.txt) file

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

  • Comment on Re: with CGI, How to have multiple usernames and passwords from a txt file (password.txt) file
  • Download Code

Replies are listed 'Best First'.
Re^2: with CGI, How to have multiple usernames and passwords from a txt file (password.txt) file
by theravadamonk (Scribe) on Sep 26, 2018 at 10:27 UTC

    Hi

    Thanks for writing the code with $didmsg flag and "last". $didmsg is something new for me. This is the first time I used it. It is really what I expected. Now it's time to add security, just as Monk grand farther says. But, it is still difficult to understand it even it is a very little extra work. ( i.e - Digest::MD5::md5_hex ). I am still unable to include it to the code..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1223032]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2024-04-23 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found