Skip to main content

Simple management commands for benchmarking a Django project's hash settings

Project description

Provides a managment command that times the current Django project’s password hashing settings.

This is useful for comparing and optimizing hash settings for the running environment.

How to install

  • Install the package: pip install hash_benchmark;

  • Add 'hash_benchmark', to your INSTALLED_APPS in settings.py;

Optional but strongly recommended:

  • pip install argon2_cffi.

How to use

Install this package as per the above instructions in your project on hardware typical for your project’s production environment.

Run the management command with your current password hashing settings and take a note of the performance:

# Tests hashing performance of your installations pbkdf2_sha256
# algorithm with 100,000 iterations
> python manage.py hash_password -i 100000

Python: 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
Django: 1.9.7
Using "pbkdf2_sha256" w/parameters (100000), verification takes, on average, 0.0821s

Now, decide if this “work factor” (average password verification duration) is appropriate for your project’s needs. Your goal is to spend as much time hashing as possible and still have acceptable performance for your users during password verification.

Important considerations for choosing the right work-level are:

  • Considerations for a higher work-factor:

    • Stronger protection of your hashed passwords against brute- force attacks, possibly requiring less frequent forced password change policies for your users

  • Considerations for a lower work-factor:

    • Faster log-ins for users;

    • Better site performance when many users are logging-in simultaneously;

    • Large work-factors can be exploited remotely to cause DDoS attacks on your site

Armed with this management command, you can now make informed decisions about the settings to use for PBKDF2_SHA256 and its iterations parameter.

Switching to Argon2

Argon2 is a newer password hashing algorithm that is supported in Django 1.10 when the 3rd-party library argon2_cffi is installed (see above). Argon2 is designed to be more resilient to GPU-based brute-force attacks.

The argon2_cffi implementation is already very fast due to the fact that it is implemented as a compile C-library and is multi-threaded. This already makes it significantly faster than anything written in Python.

Casual anecdotal evidence from the internet collated by this author in Jan 2017 suggests that for the same duration of work (in seconds), a Django installation configured to run Argon2 is estimated to be about 1,500X more resilient than a SHA256-based algorithm against GPU-based brute-force attacks.

Notice:

Please do not make important decisions based on these figures, do your own research!

If Argon2 is right for your project, it is suggested that the parallelism parameter should be set to 2X the number of CPUs in your system. The memory_cost should be adapted to your environment. The default value is 1,536K bytes, which is reasonably small and should be a safe value for almost any environment. A higher memory_cost value may provide even better resilience against GPUs. The time_cost remains to be set according to how long your project is willing to spend verifying a password.

For more information read: https://argon2-cffi.readthedocs.io/en/stable/parameters.html

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

hash_benchmark-0.2.0.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file hash_benchmark-0.2.0.tar.gz.

File metadata

File hashes

Hashes for hash_benchmark-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7d46ddd8dc6c2ebba236f79c3fdc05fd8e1fe01fea039e898228c20e59f24d38
MD5 032162f214aa18c412fea678427c04df
BLAKE2b-256 a29b9a8fe63371283d8c240c1d907633e9d94223ac762b7e0166a56be30e561c

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