Beispiel #1
0
    def addPass():
        # ask the user what catagory the password is in, and where the password is used
        if PasswordManager.mstrPWStor.keys().__str__() == "dict_keys([])":
            catagory = input("What do you want to call your first catagory? ")
            passFor = input("Where is this password going to be used? ")
        else:
            while True:
                catagory = input(f"What category is this password; {useful.Strings.lstToStr(PasswordManager.mstrPWStor, ', ', False)}, or enter a new name to create a new catagory? ")
                passFor = input("Where is this password going to be used? ")
                break

        # ask the user what the password is, or generate one for them
        ui = getpass("Type a password, or put a number 1 to 3 for a password with that strength to be generated, 1 being super weak, 3 being super strong: ")
        while True:
            useful.Terminal.clear()
            if ui.isdigit():
                if 3 <= int(ui) + 2 <= 5:
                    if not catagory in PasswordManager.mstrPWStor:
                        PasswordManager.mstrPWStor[catagory] = {}
                    randPass = Password( Generator.genPass(int(ui) + 2) )
                    PasswordManager.mstrPWStor[catagory][passFor] = randPass.getPass()
                    break
            else:
                passTemp = Password(ui)
                if passTemp.check():
                    if not catagory in PasswordManager.mstrPWStor:
                        PasswordManager.mstrPWStor[catagory] = {}
                    PasswordManager.mstrPWStor[catagory][passFor] = passTemp.getPass()
                    break
            ui = getpass("That password was insecure, type a password, or put a number 1 to 3 for a password with that strength to be generated, 1 being super weak, 3 being super strong: ")
    def edit():
        # ask the user what catagory the password is in
        PasswordManager.listPass()
        cat = input(f"What category is the password in ")
        while not cat in PasswordManager.mstrPWStor:
            useful.Terminal.clear()
            PasswordManager.listPass()
            cat = input("That's not a category, try again ")

        # ask the user where the password gets used
        useful.Terminal.clear()
        PasswordManager.listPass()
        place = input("What is the password to ")
        while not place in PasswordManager.mstrPWStor[cat]:
            useful.Terminal.clear()
            PasswordManager.listPass()
            place = input("That place isn't in the records, try again ")

        # ask the user what they want the new password to be, or generate one for them
        ui = getpass(
            "Type a password, or put a number 1 to 3 for a password with that strength to be generated, 1 being super weak, 3 being super strong: "
        )
        while True:
            useful.Terminal.clear()
            if ui.isdigit():
                if 3 <= int(ui) + 2 <= 5:
                    if not cat in PasswordManager.mstrPWStor:
                        PasswordManager.mstrPWStor[cat] = {}
                    randPass = Password(Generator.genPass(int(ui) + 2))
                    PasswordManager.mstrPWStor[cat][place] = randPass.getPass()
                    break
            else:
                passTemp = Password(ui)
                if passTemp.check():
                    if not cat in PasswordManager.mstrPWStor:
                        PasswordManager.mstrPWStor[cat] = {}
                    PasswordManager.mstrPWStor[cat][place] = passTemp.getPass()
                    break
            ui = getpass(
                "That password was insecure, type a password, or put a number 1 to 3 for a password with that strength to be generated, 1 being super weak, 3 being super strong: "
            )
Beispiel #3
0
    def genPass(strength):

        while True:
            numCap = random.randint(0, 4)
            numLet = random.randint(0, 4)
            numSpecChar = random.randint(0, 4)
            numNums = random.randint(0, 4)

            password = ""
            specChars = "!@#$%^&()"
            pwNoRand = ""

            # assign random capitol letters based on how many are requested
            for i in range(numCap):
                pwNoRand += (chr(random.randint(65, 90)))

            # assign random lowercase letters based on how many are requested
            for i in range(numLet):
                pwNoRand += (str(chr(random.randint(65, 90))).lower())

            # assign random digits based on how many are requested
            for i in range(numNums):
                pwNoRand += (str(random.randint(0, 9)))

            # assign random special characters based on how many are requested
            for i in range(numSpecChar):
                pwNoRand += (str(specChars[random.randint(
                    0,
                    len(specChars) - 1)]))

            # randomize the order of string created above
            for i in range(len(pwNoRand)):
                num = random.randint(0, len(pwNoRand) - 1)
                password += pwNoRand[num]
                # https://stackoverflow.com/questions/14198497/remove-char-at-specific-index-python
                pwNoRand = pwNoRand[:num] + pwNoRand[num + 1:]

            passAttempt = Password(password)
            if passAttempt.check(strength):
                return passAttempt.getPass()