Rework everything
This commit is contained in:
27
www/.php/auth.inc
Normal file
27
www/.php/auth.inc
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
require "credentials.inc";
|
||||
|
||||
function authenticate(): void {
|
||||
global $CREDENTIALS;
|
||||
if (!isset($_SEVER['PHP_AUTH_USER']) || !isset($_SEVER['PHP_AUTH_PW']) ||
|
||||
!array_key_exists($_SERVER['PHP_AUTH_USER'], $CREDENTIALS) ||
|
||||
$_SERVER['PHP_AUTH_PW'] !== $CREDENTIALS[$_SERVER['PHP_AUTH_USER']])
|
||||
{
|
||||
header('Status: 401');
|
||||
header('WWW-Authenticate: Basic realm="Elwig"');
|
||||
exit("401 Unauthorized :(\n");
|
||||
}
|
||||
}
|
||||
|
||||
function authenticate_client(string $client): void {
|
||||
global $CLIENT_CREDENTIALS;
|
||||
$credentials = $CLIENT_CREDENTIALS[$client];
|
||||
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
|
||||
!array_key_exists($_SERVER['PHP_AUTH_USER'], $credentials) ||
|
||||
$_SERVER['PHP_AUTH_PW'] !== $credentials[$_SERVER['PHP_AUTH_USER']])
|
||||
{
|
||||
header('Status: 401');
|
||||
header('WWW-Authenticate: Basic realm="Elwig"');
|
||||
exit("401 Unauthorized :(\n");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user