Skip to content

Instantly share code, notes, and snippets.

@rahulmr
Forked from markito/hashSHASalt.py
Created June 15, 2021 04:57
Show Gist options
  • Save rahulmr/ea43e0956c23e14668fbc13727d56ad9 to your computer and use it in GitHub Desktop.
Save rahulmr/ea43e0956c23e14668fbc13727d56ad9 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