Created
July 28, 2017 03:18
-
-
Save markito/30a9bc2afbbfd684b31986c2de305d20 to your computer and use it in GitHub Desktop.
Hashing using SHA256/Salt in Python
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
| 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment