Defining the User class

This class definition provides an example of a definition of an individual User object:

  1. 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.

  1. Define the User class:
        class User: 
  1. 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.

  1. Most of the time, we'll create users from a JSON document. ...

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.