Last active
February 6, 2023 04:11
-
-
Save PavelPolyakov/1084bd3e635a5ee146a7 to your computer and use it in GitHub Desktop.
Laravel the very basic auth filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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