src/Generics/Util/BasicAuth.php
public function auth($file = ''): bool
    {
        if (php_sapi_name() == 'cli') {
            throw new GenericsException("CLI does not support basic auth!");
        }
        
        if ($file && in_array($file, $this->whitelist)) {
            return true;
        }
        
        $user = null;
        $password = null;
        
        if (isset($_SERVER['PHP_AUTH_USER'])) {
            $user = $_SERVER['PHP_AUTH_USER'];
        }
        if (isset($_SERVER['PHP_AUTH_PW'])) {
            $password = $_SERVER['PHP_AUTH_PW'];
        }
        
        if ($user && $password && $user == $this->user && $password == $this->password) {
            return true;
        }
        
        $httpStatus = new HttpStatus(401, '1.0');
        header('WWW-Authenticate: Basic realm=' . $this->realm);
        header(sprintf('HTTP/%s', $httpStatus));
        echo "Forbidden!";
        return false;
    }
public function auth($file = ''): bool
    {
        if (php_sapi_name() == 'cli') {
            throw new GenericsException("CLI does not support basic auth!");
        }
        
        if ($file && in_array($file, $this->whitelist)) {
            return true;
        }
        
        $user = null;
        $password = null;
        
        if (isset($_SERVER['PHP_AUTH_USER'])) {
            $user = $_SERVER['PHP_AUTH_USER'];
        }
        if (isset($_SERVER['PHP_AUTH_PW'])) {
            $password = $_SERVER['PHP_AUTH_PW'];
        }
        
        if ($user && $password && $user == $this->user && $password == $this->password) {
            return true;
        }
        
        $httpStatus = new HttpStatus(401, '1.0');
        header('WWW-Authenticate: Basic realm=' . $this->realm);
        header(sprintf('HTTP/%s', $httpStatus));
        echo "Forbidden!";
        return false;
    }
Perform authentication

@param string $file
@throws GenericsException
@return bool