Implementing SHA in a real-world scenario

The following is an example of real-life SHA implementation.

Getting ready

For this script, we will need the hashlib library and the uuid library.

How to do it…

For this real-world example, we will be implementing an SHA256 encoding scheme and generating a salt to make it even more secure by defeating precomputed hash tables. We will then run it through password-checking to ensure the password was typed correctly:

#!/usr/bin/python import uuid import hashlib # Let's do the hashing. We create a salt and append it to the password once hashes. def hash(password): salt = uuid.uuid4().hex return hashlib.sha512(salt.encode() + password.encode()).hexdigest() + ':' + salt # Let's confirm that worked as intended. def ...

Get Python: Penetration Testing for Developers 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.