没有设置数据库的基本laravel路由密码保护? [英] Basic laravel route password protection without setting up database?
本文介绍了没有设置数据库的基本laravel路由密码保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找对域(example.com/demo)无效的简单密码保护解决方案(用户名和密码作为键值对存储在数组中).我知道这是生产中的不良做法,但这只是对某人的快速演示.我目前拥有的代码非常简单:
I'm looking for a dead simple password protection solution (username and password stored as key-value pair in array) to a domain (example.com/demo). I know this is bad practice in production but this is just a quick demo to someone. The code I have currently is pretty trivial stuff:
Route::group(['prefix' => 'demo', 'before' => 'auth.basic'], function() {...});
我必须创建自己的过滤器吗?我将如何设置它以使其仅在生产中起作用?
Would I have to create my own filter? How would I set it so the filter only works in production?
推荐答案
这很简单:
Route::filter('auth.verybasic', function()
{
if(Request::getUser() != 'foo' || Request::getPassword() != 'bar'){
$headers = array('WWW-Authenticate' => 'Basic');
return Response::make('Invalid credentials.', 401, $headers);
}
});
关于环境限制,只需使用App::environment()
进行检查:
Regarding the environment restriction, just check with App::environment()
:
Route::filter('auth.verybasic', function()
{
if(App::environment() != 'production') return;
// check login (same as above)
});
这篇关于没有设置数据库的基本laravel路由密码保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文