Search code examples
djangoformsauthenticationdefaultrecaptcha

Is it needed to add reCaptcha to built in Django's login form?


Hello I'm new to Django and I'm using Django's built in forms to login my users, also I have a contact form where I'm using Google reCaptcha to avoid attacks.

I was wondering if it is needed to add reCaptcha to my login form. I have heard Django takes care most of security and I don't want to repeat code if default login form is already prepared for brute force attacks.

In case its better to add reCaptcha to default login form how can I process the validation? In my contact form I call Google's API to verify user click within my views, but I don't feel comfortable adding that code inside the auth_views.LoginView class.

Thanks!


Solution

  • Django does not take care of any rate-limiting with its forms, including login.

    I think that it is a good idea to include some sort of rate-limiting security measure to your login form. re-Captcha might be overkill as a default, unless there are several incorrect attempts within a timeframe.

    Take a look at the Django rate-limit project for an easy to implement alternative to captcha.

    In order to add reCaptcha to the login view, rather than modifying the auth_views.LoginView class, just create a new view that extends that class. You can add your recaptcha form validation just like in your contact form.

    Then you can update your url to point to your custom view and template:

    url(r'^login/$', custom_auth_views.recaptcha_login, {'template_name': 'core/recaptcha_login.html'}, name='login'),
    

    See this post on how to extend the login views / templates.