Skip to content

Instantly share code, notes, and snippets.

@markito
Created July 28, 2017 03:18
Show Gist options
  • Select an option

  • Save markito/30a9bc2afbbfd684b31986c2de305d20 to your computer and use it in GitHub Desktop.

Select an option

Save markito/30a9bc2afbbfd684b31986c2de305d20 to your computer and use it in GitHub Desktop.

Revisions

  1. markito renamed this gist Jul 28, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. markito created this gist Jul 28, 2017.
    16 changes: 16 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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()