This class definition provides an example of a definition of an individual User object:
- Import modules that are required to create and check the password:
import hashlib import os import base64
Other useful modules include json so that a User object can be properly serialized.
- Define the User class:
class User:
- Since we'll be changing some aspects of password generation and checking, we'll provide two constants as part of the overall class definition:
DIGEST = 'sha384' ROUNDS = 100000
We'll use the SHA-384 digest algorithm. This provides 64-byte summaries. We'll use 100,000 rounds for the Password-Based Key Derivation Function 2 (PBKDF2) algorithm.
- Most of the time, we'll create users from a JSON document. ...