Skip to content

Instantly share code, notes, and snippets.

@MattSegal
Last active August 22, 2017 02:34
Show Gist options
  • Save MattSegal/22d1ca54a1f0436026bb1b8ad3cb37bf to your computer and use it in GitHub Desktop.
Save MattSegal/22d1ca54a1f0436026bb1b8ad3cb37bf to your computer and use it in GitHub Desktop.
hashing stuff in python
from hashlib import sha256
def get_sha256_hash(text):
text_bytes = text.encode('utf-8')
text_hash = sha256(text_bytes)
return text_hash.hexdigest()
password_1 = 'hunter2'
password_2 = 'hunter2'
is_text_equal = password_1 == password_2
password_1_hash = get_sha256_hash(password_1)
password_2_hash = get_sha256_hash(password_2)
is_hash_equal = password_1_hash == password_2_hash
print('Password 1 ({}) has hash:\t{}'.format(password_1, password_1_hash))
print('Password 2 ({}) has hash:\t{}'.format(password_2, password_2_hash))
print('\nPasswords are equal:\t{}'.format(is_text_equal))
print('Hashes are equal:\t{}'.format(is_hash_equal))
password_3 = 'woolad1'
password_4 = 'kekekek'
is_text_equal = password_3 == password_4
password_3_hash = get_sha256_hash(password_3)
password_4_hash = get_sha256_hash(password_4)
is_hash_equal = password_3_hash == password_4_hash
print('\nPassword 3 ({}) has hash:\t{}'.format(password_3, password_3_hash))
print('Password 4 ({}) has hash:\t{}'.format(password_4, password_4_hash))
print('\nPasswords are equal:\t{}'.format(is_text_equal))
print('Hashes are equal:\t{}'.format(is_hash_equal))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment