in reply to Reading from multi line file -> CGI.pm
Update - I'm crazy. while does set $_, but I customarily chomp in the fashion above and I guess I forgot why. :-(while (chomp($_ = <FILE>)) { do stuff; }
The above code shouldn't compile. The foreach after it is also completely unnecessary (no sense looping over 1 value). Maybe it ought to look something like:
Adjust the return values to suit the logic of your program. I assume that at a minimum you might like to know if the user exists in the user list and whether or not their password is correct.my $user = $q->param('username'); my $pass = $q->param('password'); verify($user, $pass) or die "No user or password incorrect"; sub verify { my ($ck_user, $ck_pass) = @_; open FH, $user_file" or die "Can't open file, $!"; while (chomp($_=<FH>)) { my ($user, $pass) = split '\|'; if ($user eq $ck_user) { if ($pass ne crypt(ck_pass)) { return 0; } else { return 1; } } } return 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Reading from multi line file -> CGI.pm
by chromatic (Archbishop) on Jan 02, 2003 at 22:08 UTC | |
by virtualsue (Vicar) on Jan 02, 2003 at 22:37 UTC |