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
18
19// Find the autoloader
21 __DIR__ . '/../vendor/autoload.php',
22 __DIR__ . '/../../../autoload.php',
23 __DIR__ . '/vendor/autoload.php',
24
25];
26
27foreach ($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();
39if (!$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
56Sapi::sendResponse($response);
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
This class represents a single HTTP response.
Definition: Response.php:12
PHP SAPI.
Definition: Sapi.php:31
$paths
Definition: digestauth.php:20
foreach($paths as $path) $request
Definition: digestauth.php:34
$userList
This example shows how to do Digest authentication.
Definition: digestauth.php:10
$digestAuth
Definition: digestauth.php:37
$response
Definition: digestauth.php:35