Instantly share code, notes, and snippets.
markito/hashSHASalt.py
Created July 28, 2017 03:18- Star 11 (11) You must be signed in to star a gist
- Fork 2 (2) You must be signed in to fork a gist
-
Select an option
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/markito/30a9bc2afbbfd684b31986c2de305d20.js"></script> - Save markito/30a9bc2afbbfd684b31986c2de305d20 to your computer and use it in GitHub Desktop.
Select an option
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/markito/30a9bc2afbbfd684b31986c2de305d20.js"></script> Save markito/30a9bc2afbbfd684b31986c2de305d20 to your computer and use it in GitHub Desktop. Download ZIP Hashing using SHA256/Salt in Python Raw hashSHASalt.py This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters| import uuid | |
| import hashlib | |
| def hashText(text): | |
| """ | |
| Basic hashing function for a text using random unique salt. | |
| """ | |
| salt = uuid.uuid4().hex | |
| return hashlib.sha256(salt.encode() + text.encode()).hexdigest() + ':' + salt | |
| def matchHashedText(hashedText, providedText): | |
| """ | |
| Check for the text in the hashed text | |
| """ | |
| _hashedText, salt = hashedText.split(':') | |
| return _hashedText == hashlib.sha256(salt.encode() + providedText.encode()).hexdigest() |