Last active
August 14, 2023 02:26
-
-
Save FlorianWeigang/2fe04b2f3df85f7491cf to your computer and use it in GitHub Desktop.
static laravel basic.auth with username and password in config file
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 | |
/** | |
* change this definition in filters.php. | |
* | |
* the code checks if the auth parameters matches the credentials in your config file, if not | |
* a WWW-Authenticate Header will be send to the client. | |
*/ | |
Route::filter('auth.basic', function () { | |
$login = false; | |
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { | |
// check credentials from config. | |
if ( | |
$_SERVER['PHP_AUTH_USER'] === Config::get('app.username') && | |
$_SERVER['PHP_AUTH_PW'] === Config::get('app.password') | |
) { | |
$login = true; | |
} | |
} | |
if ($login === false) { | |
return Response::make('Invalid credentials.', 401, ['WWW-Authenticate' => 'Basic']]); | |
} | |
}); |
Shareed2k
commented
Feb 6, 2017
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment