<?
    $file = fopen("password.dat", "r");
    if (!$file) {
      echo "<p>Unable to open passwords file.\n";
      exit;
    }
    $pass_ok = 0;
    while (!feof($file)) {
      $line = fgets($file, 1024);
      $line = chop($line);
      $uname = strtok($line, "=");
      $passwd = strtok("=");
      if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) &&
      	($uname == $_SERVER['PHP_AUTH_USER']) && ($passwd == $_SERVER['PHP_AUTH_PW'])) {
        readfile("privileged.shtml");
        $pass_ok = 1;
        break;
      }
    }
    fclose($file);
    if ($pass_ok == 0) {
      Header("WWW-Authenticate: Basic realm=\"JG3Lecture\"");
      Header("HTTP/1.0 401 Unauthorized");
      echo "<p>The username or password you enterred was incorrect." .
       " Please click 'reload' and enter the username and password" .
       " again when prompted.";
    }
?>
