Skip to content

Instantly share code, notes, and snippets.

@markito
Created July 28, 2017 03:18
Show Gist options
  • Save markito/30a9bc2afbbfd684b31986c2de305d20 to your computer and use it in GitHub Desktop.
Save markito/30a9bc2afbbfd684b31986c2de305d20 to your computer and use it in GitHub Desktop.
Hashing using SHA256/Salt in Python
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