Added login throttling

This commit is contained in:
Graham Campbell
2014-12-29 21:58:30 +00:00
parent a1442b9d85
commit 1f71919f0b
9 changed files with 114 additions and 4 deletions

View File

@@ -123,6 +123,7 @@ return [
'Illuminate\Workbench\WorkbenchServiceProvider',
'Dingo\Api\Provider\ApiServiceProvider',
'GrahamCampbell\Throttle\ThrottleServiceProvider',
'Thujohn\Rss\RssServiceProvider',
'CachetHQ\Cachet\Support\ServiceProviders\RepositoryServiceProvider',
@@ -197,6 +198,7 @@ return [
'View' => 'Illuminate\Support\Facades\View',
'API' => 'Dingo\Api\Facade\API',
'Throttle' => 'GrahamCampbell\Throttle\Facades\Throttle',
'RSS' => 'Thujohn\Rss\RssFacade',
],

View File

@@ -0,0 +1,35 @@
<?php
/*
* This file is part of Laravel Throttle by Graham Campbell.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://bit.ly/UWsjkb.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
return [
/*
|--------------------------------------------------------------------------
| Cache Driver
|--------------------------------------------------------------------------
|
| This defines the cache driver to be used. It may be the name of any
| driver set in app/config/cache.php. Setting it to null will use the
| driver you have set as default in app/config/cache.php. Please note that
| a driver that supports cache tags is required.
|
| Default: null
|
*/
'driver' => null,
];

View File

@@ -23,6 +23,7 @@ class AuthController extends Controller
if (Auth::attempt(Input::only(['email', 'password']))) {
return Redirect::intended('dashboard');
} else {
Throttle::hit(Request::instance(), 10, 10);
return Redirect::back()
->withInput(Input::except('password'))
->with('error', 'Invalid email or password');

View File

@@ -4,6 +4,7 @@ Route::filter('is_setup', 'IsSetupFilter');
Route::filter('has_setting', 'HasSettingFilter');
Route::filter('cors', 'CORSFilter');
Route::filter('allowed_domains', 'AllowedDomainsFilter');
Route::filter('login_throttling', 'LoginThrottlingFilter');
/*
|--------------------------------------------------------------------------

View File

@@ -0,0 +1,16 @@
<?php
class LoginThrottlingFilter
{
public function filter($route, $request, $response)
{
// check if we've reached the rate limit, but don't hit the throttle yet
// we can hit the throttle later on in the if validation passes
if (!Throttle::check($request, 10, 10)) {
return Redirect::back()
->with('error', 'You have made too many login requests.');
}
return $response;
}
}

View File

@@ -2,7 +2,7 @@
Route::group(['before' => 'has_setting:app_name'], function () {
Route::get('/auth/login', ['before' => 'guest', 'as' => 'login', 'uses' => 'AuthController@showLogin']);
Route::post('/auth/login', ['before' => 'guest|csrf', 'as' => 'logout', 'uses' => 'AuthController@postLogin']);
Route::post('/auth/login', ['before' => 'guest|csrf|login_throttling', 'as' => 'logout', 'uses' => 'AuthController@postLogin']);
});
Route::get('/auth/logout', ['before' => 'auth', 'as' => 'logout', 'uses' => 'AuthController@logoutAction']);

View File

@@ -13,6 +13,7 @@
"laravel/framework": "4.2.*",
"guzzlehttp/guzzle": "~5.0",
"dingo/api": "0.8.*",
"graham-campbell/throttle": "~2.0",
"watson/validating": "0.10.*",
"thujohn/rss": "~1.0",
"doctrine/dbal": "2.5.*",

56
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "2b05058fab4b2fa831e500985b506c1f",
"hash": "def3f0fcb615467e21e9eccf44a39a73",
"packages": [
{
"name": "classpreloader/classpreloader",
@@ -768,6 +768,59 @@
],
"time": "2014-10-26 09:05:09"
},
{
"name": "graham-campbell/throttle",
"version": "v2.0.1",
"source": {
"type": "git",
"url": "https://github.com/GrahamCampbell/Laravel-Throttle.git",
"reference": "0c75b729efa7dea6ec8e4182bf3f5ebe0cb9f003"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GrahamCampbell/Laravel-Throttle/zipball/0c75b729efa7dea6ec8e4182bf3f5ebe0cb9f003",
"reference": "0c75b729efa7dea6ec8e4182bf3f5ebe0cb9f003",
"shasum": ""
},
"require": {
"illuminate/cache": "~4.1",
"illuminate/http": "~4.1",
"illuminate/support": "~4.1",
"php": ">=5.4.7"
},
"require-dev": {
"graham-campbell/testbench": "~1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"GrahamCampbell\\Throttle\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Graham Campbell",
"email": "graham@mineuk.com"
}
],
"description": "Throttle Is A Rate Limiter For Laravel 4.1/4.2",
"keywords": [
"Graham Campbell",
"GrahamCampbell",
"Laravel Throttle",
"Laravel-Throttle",
"framework",
"laravel",
"rate limit",
"throttle",
"throttling"
],
"time": "2014-10-30 13:45:51"
},
{
"name": "guzzlehttp/guzzle",
"version": "5.1.0",
@@ -3477,6 +3530,7 @@
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=5.4"
},