Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created April 11, 2019 12:30
Show Gist options
  • Save ruanbekker/4d38b3d83cfae62a8eabd3dca312ddba to your computer and use it in GitHub Desktop.
Save ruanbekker/4d38b3d83cfae62a8eabd3dca312ddba to your computer and use it in GitHub Desktop.
Hashing with Python: Hashing validations
>>> import hashlib
>>> hashlib.sha1(str.encode('testing 123')).hexdigest()
'b8dfb080bc33fb564249e34252bf143d88fc018f'

with a function:

>>> def check_hash(word):
...     myhash = hashlib.sha1(str.encode(word)).hexdigest()
...     if myhash == stored_hash:
...         return 'hash exists'
...     else:
...         return 'hash does not exist'

store hash:

>>> hashlib.sha1(str.encode('testing 123')).hexdigest()
'b8dfb080bc33fb564249e34252bf143d88fc018f'
>>> stored_hash = 'b8dfb080bc33fb564249e34252bf143d88fc018f'

test function:

>>> print(check_hash('sweet'))
hash does not exist
>>> print(check_hash('testing 123'))
hash exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment