getUser(); $password = (string) $request->getPassword(); foreach ($authorizedUsers as $authorizedUser) { $validUsername = isset($authorizedUser['username']) && hash_equals((string) $authorizedUser['username'], $username); $validPassword = isset($authorizedUser['password']) && hash_equals((string) $authorizedUser['password'], $password); if ($validUsername && $validPassword) { return $next($request); } } return $this->unauthorizedResponse($request); } private function unauthorizedResponse(Request $request): Response { if ($request->expectsJson()) { return new JsonResponse(['message' => 'Unauthorized'], Response::HTTP_UNAUTHORIZED, [ 'WWW-Authenticate' => 'Basic realm="File Upload"', ]); } return response('Unauthorized', Response::HTTP_UNAUTHORIZED, [ 'WWW-Authenticate' => 'Basic realm="File Upload"', ]); } }