Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password protect a whole django app

I am running a simple staging env on heroku and I am now looking to password protect the whole app with some sort of simple authentication

I am wondering if there is a simple app or middleware that already supports this. Have tried looking around for solutions with Heroku / Cloudflare and django, but nothing seems really straight forward.

Django 1.3.1

like image 985
ApPeL Avatar asked Nov 13 '12 10:11

ApPeL


People also ask

How to protect against a password guessing attack in Django?

A Django app can be protected against a Password Guessing Attack by implementing the following controls. Traditionally, we consider complex passwords as good passwords. The password policy is defined in such a way that mandates the users to create very complex passwords. An example of such a password policy is:

What type of password does Django use?

This means that Django will use PBKDF2 to store all passwords but will support checking passwords stored with PBKDF2SHA1, argon2, and bcrypt. The next few sections describe a couple of common ways advanced users may want to modify this setting.

How do I validate a hashed password in Django?

The django.contrib.auth.hashers module provides a set of functions to create and validate hashed passwords. You can use them independently from the User model. If you’d like to manually authenticate a user by comparing a plain-text password to the hashed password in the database, use the convenience function check_password ().

Does Django support bcrypt?

It’s not the default used by Django since it requires the use of third-party libraries, but since many people may want to use it Django supports bcrypt with minimal effort. To use Bcrypt as your default storage algorithm, do the following:


1 Answers

I use django-lockdown for exactly this purpose. It allows you to add a simple password over the whole of a dev site, without having to add in any extra auth bits on your views that aren't used outside of a dev environment. It also means you can login as admin, or regular users to test whatever your site does

https://github.com/Dunedan/django-lockdown

I use Heroku and Lockdown with this bit of code in my settings.py file

USE_LOCKDOWN = os.environ.get('USE_LOCKDOWN', 'False') == 'True'
if USE_LOCKDOWN:
    INSTALLED_APPS += ('lockdown',)
    MIDDLEWARE_CLASSES += ('lockdown.middleware.LockdownMiddleware',)
    LOCKDOWN_PASSWORDS = (os.environ.get('LOCKDOWN_PASSWORD', 'False'),)
    LOCKDOWN_URL_EXCEPTIONS = (r'^/some/url/not/locked/down/$',)

Then obviously set a config var of USE_LOCKDOWN as True on my dev site, and False on my production site so no need to change the code for either.

like image 140
Guy Bowden Avatar answered Sep 27 '22 01:09

Guy Bowden