Skip to main content

Django app that locks out users after too many failed login attempts.

Project description

Django app that locks out users after too many failed login attempts until release time expires.

Tested on Django 1.4.5.

Requirements

  • Django

Installation

  1. Install python library using pip: pip install django-cerberus

  2. Add cerberus to INSTALLED_APPS in your Django settings file

  3. Sync your database

Usage

Add cerberus.decorators.watch_logins decorator to your login view. Example:

class LoginView(FormView):
    template_name = 'example/login.html'
    form_class = AuthenticationForm

    @method_decorator(watch_logins)
    def dispatch(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            return redirect(settings.LOGIN_REDIRECT_URL)
        return super(LoginView, self).dispatch(request, *args, **kwargs)

    def form_valid(self, form):
        user = form.get_user()
        login(self.request, user)
        return super(LoginView, self).form_valid(form)

    def get_success_url(self):
        return reverse('logged_in')

Settings

CERBERUS_MAX_ATTEMPTS

Number of max failed login attempt. Default: 5.

CERBERUS_LOCKOUT_TIME

Number of seconds after the failed login attempts are forgotten in seconds. Default: 600.

Model

Each lockout model instance contains username, number of failed login attempts, IP address, user agent details, GET and POST parameters, information if lockout is locked (user tried to log in with wrong credentials at least CERBERUS_MAX_ATTEMPTS times) and if lockout is expired (based on CERBERUS_LOCKOUT_TIME).

Template

You can override cerberus/lockout.html template if you wish. There is lockout instance and lockout_time variable (CERBERUS_LOCKOUT_TIME) available in template context.

Authors

Library is by Erik Telepovsky from Pragmatic Mates. See our other libraries.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-cerberus-0.3.2.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file django-cerberus-0.3.2.tar.gz.

File metadata

File hashes

Hashes for django-cerberus-0.3.2.tar.gz
Algorithm Hash digest
SHA256 b5ad0e4ad754a26bc6b1dc99c5c8ea320e626d3718ca6026e7df1948c2b17e89
MD5 5df92d4209162941b45f4d19b3fd4e44
BLAKE2b-256 c1f648cc598b6b8fb79e739a6b587edbf774733a0d24aaaf86865eb6984eeec4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page