Skip to content

Instantly share code, notes, and snippets.

@PavelPolyakov
Last active February 6, 2023 04:11
Show Gist options
  • Save PavelPolyakov/1084bd3e635a5ee146a7 to your computer and use it in GitHub Desktop.
Save PavelPolyakov/1084bd3e635a5ee146a7 to your computer and use it in GitHub Desktop.
Laravel the very basic auth filter
<?php
// located in the /app/filters.php
/* some original code */
Route::filter('statistics.auth.basic', function() {
$user = Request::getUser();
$password = Request::getPassword();
if (!App::environment('development') &&
(
(!$user || !$password) ||
($user != Config::get('statistics-auth-basic.user') || $password != Config::get('statistics-auth-basic.password')
)) {
$response = Response::make('Not authorized', 401);
$response->header('WWW-Authenticate', 'Basic realm="statistics"');
return $response;
}
});
/* some original code */
<?php
// located in the /app/config/statistics-auth-basic.php
return array(
'user' => 'user',
'password' => 'password'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment