Flask-Argon2

October 2, 2020 ยท View on GitHub

Flask-Argon2 is a Flask extension that provides Argon2 hashing utilities for your Flask app.

Installation

Install the extension with the following command:

$ pip install flask-argon2

Usage

To use the extension simply import the class wrapper and pass the Flask app object back to here. Do so like this:

from flask import Flask
from flask_argon2 import Argon2

app = Flask(__name__)
argon2 = Argon2(app)

When using an application factory this extension can be initialized by the init_app() function.

The following Flask Configs are automatically used by init_app():

Variable NameDescription
ARGON2_TIME_COSTDefines the amount of computation realized and therefore the execution time, given in number of iterations.
ARGON2_MEMORY_COSTDefines the memory usage, given in kibibytes.
ARGON2_PARALLELISMDefines the number of parallel threads (changes the resulting hash value).
ARGON2_HASH_LENGTHLength of the hash in bytes.
ARGON2_SALT_LENGTHLength of random salt to be generated for each password.
ARGON2_ENCODINGThe Argon2 C library expects bytes. So if hash() or verify() are passed an unicode string, it will be encoded using this encoding.
The default values are the same as the argon2_cffi library.

Two primary methods are now exposed by way of the argon2 object. Use them like so:

pw_hash = argon2.generate_password_hash('secret_password')
argon2.check_password_hash(pw_hash, 'secret_password')