Comparing data

I have a script that reads the user id and password given by the user and compares it to the data in a text file. If it matches, then it goes to their page. If it doesn't match, then it goes to another page. However, if they only put in their user id, then it still goes to there page. Is there a way I can make it match only if the entire line is there?
kch011099Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

monasCommented:
most likely you made a mistake in your script. Please provide an excerpt from it where you do comparison - somebody will fix it for you...
0
kch011099Author Commented:
Here is the code I am using.


#!/usr/bin/perl

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
      @pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
      read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
      @pairs = split(/&/, $buffer);
} else {
      print "Content-type: text/html\n\n";
      print "<P>Use Post or Get";
}

foreach $pair (@pairs) {
      ($key, $value) = split (/=/, $pair);
      $key =~ tr/+/ /;
      $key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
      
      $value =~s/<!--(.|\n)*-->//g;
      
      if ($formdata{$key}) {
            $formdata{$key} .= ", $value";
      } else {
            $formdata{$key} = $value;
      }
}

open(LOG,"<../clientaccess/password.txt")||&ErrorMessage;
@logmessages = <LOG>;
close<LOG>;


$n=1;

foreach $message (@logmessages) {
if ($message =~ $formdata{$key}) {
      ($id,$pwd) = split(/,/,$formdata{$key});
    if ( $message ) {
          use CGI qw/:standard/;
          print redirect('http://www.site.com/users/'.$id);
          }
      $n++;
      }
else {
    print "Content-type: text/html\n\n";
      print "Password is incorrect. Please try again.";
      $n++;
      }
}
0
KennyIT Application ExecutiveCommented:
Your code only checks for the $key :

if ($message =~ $formdata{$key}) {

You are not checking for the $Value, which I assume is the password.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

monasCommented:
if your password.txt file is in format

user1:passwd1
user2:passwd2

and in your form there is field named "login" for login name and "passwd" for password, then IMHO
you have to change if($message.... with

if ($message eq $formdata{'login'}.':'.$formdata{'passwd'}."\n"){

if you edit password file on windows computer, you maight need to chgange "\n" to "\r\n". No extra spaces at the end of the line is allowed.

Good Look
0
olthoffCommented:
($message =~ $formdata{$key})

Since this is a pattern match I think you might find this more reliable:

($message =~ /$formdata{$key}/)

or use

$message eq $formdata{$key}
0
kch011099Author Commented:
Each piece of info. entered does not have a separate key. The key is "passwd" and the user id and password entered is the value.

passwd = user1, password

so my text file looks like this

user1, password1
user2, password2
user3, password3

etc.

I need it to compare the whole line.
0
olthoffCommented:
Then it sounds like your redirection should be like this:

open(PWD, passwordfile) || die;
while (<PWD>) {
  chomp;
  if (m/^$user/) { # The user exists
    if ("$user, $password" eq $_) {
      #The password is correct
    };
  };
};
close(PWD);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.