Skip to content

Instantly share code, notes, and snippets.

@pmav99
Created October 21, 2019 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmav99/e8e79dcc6a7f3b64c33aa79729cd217c to your computer and use it in GitHub Desktop.
Save pmav99/e8e79dcc6a7f3b64c33aa79729cd217c to your computer and use it in GitHub Desktop.
Verify jupyter / ipython password hashlib
import hashlib
import sys
if len(sys.argv) != 3:
sys.exit("Usage: python3 verify.py hash passphrase")
provided_hash = sys.argv[1]
passphrase = sys.argv[2]
salt = provided_hash.split(":")[1]
h = hashlib.new("sha1")
h.update(passphrase.encode("utf-8") + salt.encode("ascii"))
new_hash = ":".join(("sha1", salt, h.digest().hex()))
if new_hash == provided_hash:
print("OK")
else:
sys.exit("The provided passphrase is wrong")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment