Last active
October 12, 2015 23:54
-
-
Save 20after4/530c962ab99966c7b3ea to your computer and use it in GitHub Desktop.
compare hashed passwords in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
def compare_sha256(password, hashed_password): | |
m = hashlib.sha256() | |
m.update(password) | |
result = m.hexdigest() | |
return hashed_password == result | |
def password_prompt(): | |
password = raw_input("your password?") | |
return compare_sha256(password, hashed_pw) | |
def try_several_times(max_fails, message="Wrong! %s tries remaining." | |
abort_message="Too many failures"): | |
counter = max_fails | |
while (counter > 0): | |
if password_prompt(): | |
return True | |
else: | |
counter = counter - 1 | |
if (counter > 0): | |
print (message % counter) | |
exit(abort_message) | |
hashed_pw = "e62e1269317b9654e1314dfecb78f29b35ad4d362da0a9c2ccdb680aa535d7ea" | |
try_several_times(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment