Skip to content

Commit 2d9b388

Browse files
committed
also check in $_SERVER, this allows us to use SetEnv in .htaccess to set the username/password
1 parent 39209be commit 2d9b388

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/Controller/LoginController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
1111
{
1212
$postBody = $request->getParsedBody();
1313
$response = $this->getResponse();
14+
1415
// var_dump($_SESSION);
1516
if (isset($_SESSION['userid'])) {
1617
$user = $_SESSION['userid'];
@@ -20,7 +21,10 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
2021
return $response;
2122
}
2223
$response->getBody()->write("<h1>Already logged in as $user</h1>");
23-
} else if ($postBody['username'] == "admin" || ($postBody['username'] == $_ENV['USER'] && $postBody['password'] == $_ENV['PASSWORD'])) {
24+
} else if (
25+
($postBody['username'] == $_ENV['USER'] && $postBody['password'] == $_ENV['PASSWORD']) ||
26+
($postBody['username'] == $_SERVER['USER'] && $postBody['password'] == $_SERVER['PASSWORD'])
27+
) {
2428
$user = $postBody['username'];
2529
$_SESSION['userid'] = $user;
2630
if ($_GET['returnUrl']) {
@@ -37,7 +41,7 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
3741
//var_dump($_COOKIE);
3842
//echo("session:\n");
3943
//var_dump($_SESSION);
40-
$response->getBody()->write("<h1>No (try posting user=alice&password=alice123)</h1>\n");
44+
$response->getBody()->write("<h1>No (try posting username=alice&password=alice123)</h1>\n");
4145
}
4246
return $response;
4347
}

0 commit comments

Comments
 (0)