-
-
Save mahmudinm/18fb0ba776fd15f7d7717fb50ddc1fa0 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']]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment