ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
digestauth.php
Go to the documentation of this file.
1 <?php
2 
11  "user1" => "password",
12  "user2" => "password",
13 ];
14 
15 use Sabre\HTTP\Auth;
17 use Sabre\HTTP\Sapi;
18 
19 // Find the autoloader
20 $paths = [
21  __DIR__ . '/../vendor/autoload.php',
22  __DIR__ . '/../../../autoload.php',
23  __DIR__ . '/vendor/autoload.php',
24 
25 ];
26 
27 foreach ($paths as $path) {
28  if (file_exists($path)) {
29  include $path;
30  break;
31  }
32 }
33 
34 $request = Sapi::getRequest();
36 
37 $digestAuth = new Auth\Digest("Locked down area", $request, $response);
38 $digestAuth->init();
39 if (!$userName = $digestAuth->getUsername()) {
40 
41  // No username given
42  $digestAuth->requireLogin();
43 
44 } elseif (!isset($userList[$userName]) || !$digestAuth->validatePassword($userList[$userName])) {
45 
46  // Username or password are incorrect
47  $digestAuth->requireLogin();
48 } else {
49 
50  // Success !
51  $response->setBody('You are logged in!');
52 
53 }
54 
55 // Sending the response
56 Sapi::sendResponse($response);
$path
Definition: aliased.php:25
$response
Definition: digestauth.php:35
$userList
This example shows how to do Digest authentication.
Definition: digestauth.php:10
$digestAuth
Definition: digestauth.php:37
$paths
Definition: digestauth.php:20
This class represents a single HTTP response.
Definition: Response.php:12
foreach($paths as $path) $request
Definition: digestauth.php:34