الفصل السابع
11.
12.
210
البرنامج النصي http_authentication.php (تابع)
$salt = substr($from_file [1],0,2);
$user_pass = crypt ($password, $salt);
} elseif ($mode == "md5") {
$user_pass = md5 ($password);
if (rtrim($from_file [1]) == $user_pass) {
$match = 1;
break;
13.
14.
15.
}
16.
17.
18.
19.
}
20.
}
21.
}
22.
if ($match) {
23.
return 1;
24.
} else {
25.
return 0;
26.
}
27.
28.
}
29.
30.
31.
32.
fclose($fh);
function authenticate() {
33.
34.
}
35.
36.
Header ("WWW-Authenticate: Basic realm=\"RESTRICTED ACCESS\"");
Header("HTTP/1.0 401 Unauthorized");
echo ("<h1>INVALID USERNAME OR PASSWORD. ACCESS DENIED<h1>");
exit;
/*** MAIN ***/
//select md5 or crypt for $mode. md5 is for md5 encoded passwords, crypt is for passwords encoded using apache's httpasswd
$mode = "md5";
$password_file = "C:/apache/passwords/pass.txt";
if (!isset($PHP_AUTH_USER)) {
authenticate();
37.
38.
39.
40.
41.
42.
43.
44.
45.
<?
} else {
if (check_pass ($PHP_AUTH_USER, $PHP_AUTH_PW, $mode)) {
j?>
<h1>ACCEPTED</h1>
ص٢١٠