Skip to content

Commit

Permalink
update array.py
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus committed Jan 3, 2024
1 parent c197483 commit 4adcd29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
26 changes: 0 additions & 26 deletions list_comparing.py

This file was deleted.

34 changes: 21 additions & 13 deletions passbolt_api_hibp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import json
import pwnedpasswords
import sys
from os.path import exists
from tqdm import tqdm
import urllib3
from lib.pickling import *

urllib3.disable_warnings()
passbolt = passboltapi.PassboltAPI(config_path="config.ini", new_keys=True)
Expand All @@ -20,8 +22,9 @@ def load_dict(passbolt):
sys.stderr.write("Gathering resources from passbolt...\n")
D = {}
for r in tqdm(passbolt.get(url="/resources.json?api-version=v2")['body']):
password = passbolt.get_password(r['id'])
if password != None:
if ((password := passbolt.get_password(r['id'])) != None):
#password = passbolt.get_password(r['id'])
#if password != None:
t = (r['id'], r['name'],r['username'],r['uri'],r['description'])
if password not in D:
D[password] = [t]
Expand All @@ -37,36 +40,41 @@ def proc_dict(passbolt, D):
output: broken_plain_password_list
"""
sys.stderr.write("Checking passwords hashes against HIBP...\n")
broken=[]
for password in tqdm(D):
rating = pwnedpasswords.check(password, plain_text=True)
if rating > 0:
broken.append(password)
return broken
return [password for password in tqdm(D) if pwnedpasswords.check(password, plain_text=True) > 0]


def proc_pickle(D, key=None):
"""
loads a pickle and a dictinary and returns a list of keys that are not in the pickle
input dictionary
output: broken_plain_password_list
"""
filename = ".%s.pkl" % sys.argv[0]
pkldata = []
if exists(filename): pkldata = decompress_pickle(filename,key=key)
newdata = [password for password in D if password not in pkldata]
compress_pickle(filename, pkldata + newdata, key=key)
return newdata

def display_broken(broken):
"""
Display info in the dictionary using elements of broken list as key.
input: broken_plain_password_list
"""
sys.stderr.write("Results:\n")
for password in broken:
sys.stderr.write("-" * 60 + "\n")
sys.stdout.write("-" * 60 + "\n")
sys.stderr.write("broken password: %s\n" % password)
sys.stdout.write("broken password: %s\n" % password)
for t in D[password]:
msg = "id:%s, name:%s, username:%s, uri: %s, description: %s\n" % t
sys.stderr.write(msg)
sys.stdout.write(msg)
sys.stderr.flush()
sys.stdout.flush()
sys.stderr.write("Total broken: %d\n" % len(broken))
sys.stderr.flush()


if __name__ == "__main__":
D = load_dict(passbolt)
broken = proc_dict(passbolt, D)
D1 = proc_pickle(D,key=passbolt.config["PASSBOLT"]["PASSPHRASE"])
broken = proc_dict(passbolt, D1)
display_broken(broken)

0 comments on commit 4adcd29

Please sign in to comment.