我用
django创建了一个网站.用户应该能够登录.登录视图如下所示:
from django.contrib.auth import authenticate,login from django.contrib.auth.models import User .... if request.method == 'POST': username = request.POST['username']#get username password = request.POST['txtPwd']# and password user = authenticate(username=username,password=password) #checking username and pwd if user is not None: if user.is_active: login(request,user)
但凭借这种“解决方案”,我无法应对蛮力攻击.所以我环顾四周发现了这个:
Throttling brute force login attacks in Django
第一个答案是有帮助的.我选择了django-axes因为django-ratelimit只计算调用视图的数量.
但这是我的问题:当我尝试使用错误的密码登录时,它不计算失败. (仅限于/ admin-section).
我找不到将我的登录视图“添加”到django-axes的选项.
所以这是我的问题:
编辑:
这是我的设置文件:
INSTALLED_APPS = ( 'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','axes',) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware','axes.middleware.FailedLoginMiddleware' ) ... AXES_LOCK_OUT_AT_FAILURE = False AXES_USE_USER_AGENT = True AXES_COOLOFF_TIME = 1 AXES_LOGIN_FAILURE_LIMIT = 50