----- Original Message -----
From: David Gilden <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, April 21, 2001 2:49 AM
Subject: Populating Hashs and checking multi form fields



> # stuff $pwd in to @indata
> open(FILE,$pwfile) || die &dead("Can't find $pwfile. $!");
> @indata = <FILE>;
This will only read one line from the file, Is that what you want? If no
use: @indata = FILE->getlines();
> close(FILE);
>
> # populate a hash , I am guessing here!
> foreach (@indata){
> ($x,$y) = split(/\|/,$_);
> $users{$x} = $y;
> }
You might do the chomp in the loop above
> ($x,$y) = split(/\|/,chomp($_));
>
> # loop and process each record from $pwd
> foreach $i (@indata) {
> #remove hard return character from each record
> chomp($i);
>
> #split fields on pipe character
> #assign a variable name to each of the fields
> ($username,$password) = split(/\|/,$i);

whats code above this doing? Yuo did already split it.
>
> ## want to check here and if something is not matching call our sub &dead
> while (($test_username,$test_password) = each %users) {
> # print "$test_username,$test_password\n";
> # print "$in{'name'} $in{'pwd'} \n";
> #&dead("Bad username , Sorry") if ($in{'name'} ne $test_username);
> #&dead("Password, Sorry") if ($in{'pwd'} ne $test_password);
> }
>
You dont want to give people information on what is wrong when they are
guessing username or password.


Try something like this


&dead("Password, Sorry") if !authorize($user, $pwd);

Sub autorhorize{

  my ($user, $pwd) =@_;
  open (FH, "<$pwfile") || die $!;
  while (<FH>) {
     return 1 if $_ eq "$user|$pwd";
  }
}




Reply via email to