How to use pyhibp - 6 common examples

To help you get started, we’ve selected a few pyhibp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matamorphosis / Scrummage / lib / plugins / Have_I_Been_Pwned.py View on Github external
elif Type_of_Query == "account":
            Local_Plugin_Name = Plugin_Name + "-" + Type_of_Query
            Cached_Data = General.Get_Cache(Directory, Local_Plugin_Name)

            if not Cached_Data:
                Cached_Data = []

            for Query in Query_List:
                Query_Response = pyhibp.get_account_breaches(account=Query, truncate_response=True)

                if Query_Response:
                    Current_Step = 0

                    for Response in Query_Response:
                        Current_Response = pyhibp.get_single_breach(breach_name=Response['Name'])
                        JSON_Query_Response = json.dumps(Current_Response, indent=4, sort_keys=True)
                        Link = "https://" + Current_Response['Domain']

                        if Current_Response['Domain'] not in Cached_Data and Current_Response['Domain'] not in Data_to_Cache and Current_Step < int(Limit):
                            Output_file = General.Create_Query_Results_Output_File(Directory, Query, Local_Plugin_Name, JSON_Query_Response, "account", The_File_Extension)

                            if Output_file:
                                Output_Connections = General.Connections(Query, Local_Plugin_Name, Current_Response['Domain'], "Data Leakage", Task_ID, Local_Plugin_Name.lower())
                                Output_Connections.Output([Output_file], Link, General.Get_Title(Link), Concat_Plugin_Name)

                            Data_to_Cache.append(Current_Response['Domain'])
                            Current_Step += 1

            if Cached_Data:
                General.Write_Cache(Directory, Data_to_Cache, Local_Plugin_Name, "a")
github matamorphosis / Scrummage / lib / plugins / Have_I_Been_Pwned.py View on Github external
if Cached_Data:
                General.Write_Cache(Directory, Data_to_Cache, Local_Plugin_Name, "a")

            else:
                General.Write_Cache(Directory, Data_to_Cache, Local_Plugin_Name, "w")

        elif Type_of_Query == "breach":
            Local_Plugin_Name = Plugin_Name + "-" + Type_of_Query
            Cached_Data = General.Get_Cache(Directory, Local_Plugin_Name)

            if not Cached_Data:
                Cached_Data = []

            for Query in Query_List:
                Query_Response = pyhibp.get_single_breach(breach_name=Query)

                if Query_Response:
                    Domain = Query_Response["Domain"]
                    Link = "https://www." + Domain + ".com/"
                    JSON_Query_Response = json.dumps(Query_Response, indent=4, sort_keys=True)

                    if Link not in Cached_Data and Link not in Data_to_Cache:
                        Output_file = General.Create_Query_Results_Output_File(Directory, Query, Local_Plugin_Name, JSON_Query_Response, "breach", The_File_Extension)

                        if Output_file:
                            Output_Connections = General.Connections(Query, Local_Plugin_Name, "haveibeenpwned.com", "Data Leakage", Task_ID, Local_Plugin_Name.lower())
                            Output_Connections.Output([Output_file], Link, General.Get_Title(Link), Concat_Plugin_Name)

                        Data_to_Cache.append(Link)

            if Cached_Data:
github matamorphosis / Scrummage / lib / plugins / Have_I_Been_Pwned.py View on Github external
if Cached_Data:
                General.Write_Cache(Directory, Data_to_Cache, Local_Plugin_Name, "a")

            else:
                General.Write_Cache(Directory, Data_to_Cache, Local_Plugin_Name, "w")

        elif Type_of_Query == "account":
            Local_Plugin_Name = Plugin_Name + "-" + Type_of_Query
            Cached_Data = General.Get_Cache(Directory, Local_Plugin_Name)

            if not Cached_Data:
                Cached_Data = []

            for Query in Query_List:
                Query_Response = pyhibp.get_account_breaches(account=Query, truncate_response=True)

                if Query_Response:
                    Current_Step = 0

                    for Response in Query_Response:
                        Current_Response = pyhibp.get_single_breach(breach_name=Response['Name'])
                        JSON_Query_Response = json.dumps(Current_Response, indent=4, sort_keys=True)
                        Link = "https://" + Current_Response['Domain']

                        if Current_Response['Domain'] not in Cached_Data and Current_Response['Domain'] not in Data_to_Cache and Current_Step < int(Limit):
                            Output_file = General.Create_Query_Results_Output_File(Directory, Query, Local_Plugin_Name, JSON_Query_Response, "account", The_File_Extension)

                            if Output_file:
                                Output_Connections = General.Connections(Query, Local_Plugin_Name, Current_Response['Domain'], "Data Leakage", Task_ID, Local_Plugin_Name.lower())
                                Output_Connections.Output([Output_file], Link, General.Get_Title(Link), Concat_Plugin_Name)
github matamorphosis / Scrummage / lib / plugins / Have_I_Been_Pwned.py View on Github external
pyhibp.set_api_key(key=Load_Configuration())

        except:
            logging.warning(f"{General.Date()} - {__name__.strip('plugins.')} - Failed to set API key, make sure it is set in the configuration file.")

        Query_List = General.Convert_to_List(Query_List)

        if Type_of_Query == "email":
            Local_Plugin_Name = Plugin_Name + "-" + Type_of_Query
            Cached_Data = General.Get_Cache(Directory, Local_Plugin_Name)

            if not Cached_Data:
                Cached_Data = []

            for Query in Query_List:
                Query_Response = pyhibp.get_pastes(email_address=Query)
                logging.info(Query_Response)

                if Query_Response:
                    Domain = Query_Response[0]["Source"]
                    ID = Query_Response[0]["Id"]
                    Link = "https://www." + Domain + ".com/" + ID
                    JSON_Query_Response = json.dumps(Query_Response, indent=4, sort_keys=True)

                    if Link not in Cached_Data and Link not in Data_to_Cache:
                        Output_file = General.Create_Query_Results_Output_File(Directory, Query, Plugin_Name, JSON_Query_Response, "email", The_File_Extension)

                        if Output_file:
                            Output_Connections = General.Connections(Query, Local_Plugin_Name, "haveibeenpwned.com", "Data Leakage", Task_ID, Local_Plugin_Name.lower())
                            Output_Connections.Output([Output_file], Link, General.Get_Title(Link), Concat_Plugin_Name)

                        Data_to_Cache.append(Link)
github matamorphosis / Scrummage / lib / plugins / Have_I_Been_Pwned.py View on Github external
if Cached_Data:
                General.Write_Cache(Directory, Data_to_Cache, Local_Plugin_Name, "a")

            else:
                General.Write_Cache(Directory, Data_to_Cache, Local_Plugin_Name, "w")

        elif Type_of_Query == "password":
            Local_Plugin_Name = Plugin_Name + "-" + Type_of_Query
            Cached_Data = General.Get_Cache(Directory, Local_Plugin_Name)

            if not Cached_Data:
                Cached_Data = []

            for Query in Query_List:
                Query_Response = pw.is_password_breached(password=Query)
                logging.info(Query_Response)

                if Query_Response:
                    Link = "https://haveibeenpwned.com/Passwords?" + Query

                    if Link not in Cached_Data and Link not in Data_to_Cache:
                        Output_file = General.Create_Query_Results_Output_File(Directory, Query, Plugin_Name, str(Query_Response), "password", ".txt")

                        if Output_file:
                            Output_Connections = General.Connections(Query, Local_Plugin_Name, "haveibeenpwned.com", "Data Leakage", Task_ID, Local_Plugin_Name.lower())
                            Output_Connections.Output([Output_file], Link, General.Get_Title(Link), Concat_Plugin_Name)

                        Data_to_Cache.append(Link)

            if Cached_Data:
                General.Write_Cache(Directory, Data_to_Cache, Local_Plugin_Name, "a")
github matamorphosis / Scrummage / lib / plugins / Have_I_Been_Pwned.py View on Github external
Limit = 10

        Directory = General.Make_Directory(Concat_Plugin_Name)

        logger = logging.getLogger()
        logger.setLevel(logging.INFO)

        Log_File = General.Logging(Directory, Concat_Plugin_Name)
        handler = logging.FileHandler(os.path.join(Directory, Log_File), "w")
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter("%(levelname)s - %(message)s")
        handler.setFormatter(formatter)
        logger.addHandler(handler)

        try:
            pyhibp.set_api_key(key=Load_Configuration())

        except:
            logging.warning(f"{General.Date()} - {__name__.strip('plugins.')} - Failed to set API key, make sure it is set in the configuration file.")

        Query_List = General.Convert_to_List(Query_List)

        if Type_of_Query == "email":
            Local_Plugin_Name = Plugin_Name + "-" + Type_of_Query
            Cached_Data = General.Get_Cache(Directory, Local_Plugin_Name)

            if not Cached_Data:
                Cached_Data = []

            for Query in Query_List:
                Query_Response = pyhibp.get_pastes(email_address=Query)
                logging.info(Query_Response)

pyhibp

An interface to Troy Hunt's 'Have I Been Pwned' public API

AGPL-3.0
Latest version published 4 years ago

Package Health Score

33 / 100
Full package analysis