check.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import requests
  2. import csv
  3. import hashlib
  4. from time import sleep
  5. api_link = 'https://api.pwnedpasswords.com/range/'
  6. ses = requests.Session()
  7. with open('pass.csv', newline='') as csvfile:
  8. file = csv.DictReader(csvfile, delimiter=',', quotechar='"')
  9. for row in file:
  10. # print(row['Password'])
  11. raw_pass = row['Password']
  12. sha1_pass = hashlib.sha1(raw_pass.encode()).hexdigest()
  13. sha1_five = sha1_pass[:5]
  14. # sha1_rest = sha1_pass[5:]
  15. result = ses.get(api_link + sha1_five)
  16. if result.status_code == 200:
  17. # print(' ', result.text)
  18. result_file = result.text
  19. lines = result_file.split('\r\n')
  20. for line in lines:
  21. # print(line)
  22. sha1_rest, num_breaches = line.split(':')
  23. # if (sha1_five + sha1_rest == sha1_pass) and (num_breaches > 0):
  24. if (sha1_five + sha1_rest.lower() == sha1_pass):
  25. print(row['Title'] + '[' + row['Username'] + '] [' + raw_pass + '] has been compromised', num_breaches, 'times.')
  26. sleep(1.5)
  27. # break