Retrieving or saving credentials from and to the database
From a theoretical point of view, we have already discussed what a hash is and why we should use one. From a practical point of view, there are many Python packages available (for example, sha256
and pycrypto
), but one of the easiest to use that’s also very effective is hashlib
. This library is installed in Python by default, so we don’t have to install it in our virtual environment; all we have to do is import it into our app.py
file.
While leveraging hashlib
, all we need to do is use its sha256
method to create the hash encryption of the password. Once again, let me highlight that SHA-256 is a very strong form of encryption from a security perspective.
These are the new lines of code we need for the hashing process:
Figure 13.17: The make_hashes function
Here’s a breakdown of what we did:
- On line 5, we imported
hashlib
. - On lines 12 and 13, we created a new...