# function that will check to ensure the username are # password match and are ok sub checkLogin { my ($loginname) = @_; open USERFILE, " $SETTINGS{'userfile'}" || die "Failed to open file: $!"; if ($^O ne "MSWin32") { flock(USERFILE, LOCK_EX); } while (<USERFILE>) { my @fields = split(/\t/,$_); # split $line, using : as delimiter if (@fields[1]=~m/^$loginname$/) { if (@fields[2]=~m/^$password$/) { $matchokay='true'; # login name matches password } } } close(USERFILE); if ($matchokay) { return $matchokay; } else { return ''; } }
Example 1: Hard-to-read code.