Skip to content

Instantly share code, notes, and snippets.

@missett
Created January 19, 2019 22:52
Show Gist options
  • Save missett/daf30cbf077dfeab695d62e98b6b9cc1 to your computer and use it in GitHub Desktop.
Save missett/daf30cbf077dfeab695d62e98b6b9cc1 to your computer and use it in GitHub Desktop.
Checks a list of passwords against Have I Been Pwned to find which passwords you should change
#! /usr/bin/env python
import hashlib
import httplib
with open("passwords.txt", "r") as file:
for password in file:
password = password.strip()
sha = hashlib.sha1(password).hexdigest().upper()
head = sha[:5]
tail = sha[5:]
uri = "/range/%s" % head
connection = httplib.HTTPSConnection("api.pwnedpasswords.com")
connection.request("GET", uri)
response = connection.getresponse().read()
for entry in response.splitlines():
fullhash, count = entry.split(":")
# print(fullhash)
if fullhash == tail:
print "%s found %s times" % (password, count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment