Skip to content

Instantly share code, notes, and snippets.

@pmav99
Created October 21, 2019 09:36
Show Gist options
  • Save pmav99/e8e79dcc6a7f3b64c33aa79729cd217c to your computer and use it in GitHub Desktop.
Save pmav99/e8e79dcc6a7f3b64c33aa79729cd217c to your computer and use it in GitHub Desktop.

Revisions

  1. pmav99 created this gist Oct 21, 2019.
    18 changes: 18 additions & 0 deletions verify_password.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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")