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: ")
Beispiel #2
0
class WordSegXML(PyWordSeg, XMLParser):
    def __init__(self, inifile, passfile=None):
        PyWordSeg.__init__(self, inifile)
        XMLParser.__init__(self)
        if passfile:
            self.password = Password(passfile)
            self.auth = True
        else:
            self.auth = False

    def authenticate(self):
        if self.auth == False:
            return True
        info = self.getUserInfo()
        ret = self.password.check(info['username'], info['password'])
        return ret

    def ProcessXML(self, inbuf_xml):
        parse_ok = self.parseString(inbuf_xml)

        if not parse_ok:
            return (2, 'xml format error.')

        if self.authenticate() == False:
            return (3, 'user or password error.')

        textL = self.getText().strip("\r\n").split("\n")
        outL = self.ApplyList(textL)
        outXML = self.XMLStringListWrap(outL, "UTF-8")
        return (1, outXML)
class WordSegXML(PyWordSeg, XMLParser):
    def __init__(self, inifile, passfile=None):
        PyWordSeg.__init__(self, inifile)
	XMLParser.__init__(self)
	if passfile:
	    self.password=Password(passfile)
	    self.auth=True
	else:
	    self.auth=False

    def authenticate(self):
        if self.auth==False:
	    return True
        info=self.getUserInfo()
	ret=self.password.check(info['username'], info['password'])
	return ret

    def ProcessXML(self, inbuf_xml):
        parse_ok=self.parseString(inbuf_xml)

	if not parse_ok:
	    return (2,'xml format error.')

	if self.authenticate()==False:
	    return (3,'user or password error.')

	textL=self.getText().strip("\r\n").split("\n")
	outL=self.ApplyList(textL)
	outXML=self.XMLStringListWrap(outL,"UTF-8")
	return (1, outXML)
    def login():

        # if pathToFile.is_file(): os.remove(pathToFile)

        # if the login file doesn't exist, have the user create an account
        if not pathToLoginFile.is_file():
            firstName = input("What is your first name? ")
            lastName = input("What is your last name? ")
            loginUser = input('What do you want your username to be? ')
            loginPass = Password(
                getpass('What do you want as your password? '))
            # os.removedirs(Path( pathToDir ))

            # loops until the user puts in a max strength password, a strength of 5
            while True:
                if loginPass.check(5):
                    namePass = f"{rBrkt}'First name' : '{firstName}', 'Last name' : '{lastName}', 'UserName' : '{loginUser}', 'Password' : '{loginPass.txt}'{lBrkt}"

                    # generate a key based on the namePass string, then encrypt namePass with that key, that key is also the global encryption key
                    CryptoGraphy.genKey(namePass, pathToDir)
                    CryptoGraphy.encrypt(namePass, f"{pathToDir}",
                                         f"{pathToLoginFile}")
                    break
                # set the txt value of loginPass to the ui
                loginPass.set(
                    getpass(
                        'That password is not very secure, try a different one: '
                    ))

        # if the login file exists
        if pathToLoginFile.is_file():
            namePass = CryptoGraphy.decrypt(pathToLoginFile, pathToDir)
            # namePass is decrypted into a string, so eval it to turn it into the dictionary it is
            namePass = eval(namePass)
            username = namePass["UserName"]
            password = namePass["Password"]

            fails = 0
            while True:
                useful.Terminal.clear()
                print(f"Attempts: {fails}")
                if fails == 3:
                    useful.Terminal.clear()
                    print("You have reached the maximum number of attempts.")
                    quit()

                fails += 1
                if useful.Terminal.inputChecker(
                        input("What's your username? "),
                        username) and useful.Terminal.inputChecker(
                            getpass("What's your password? "), password):
                    break

            PasswordManager.openApp()
    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 #6
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()
Beispiel #7
0
    def run(self):
        while (True):
            password = None
            self.condition.acquire()
            try:
                pw = self.queue.get(block=False)
                password = Password(pw)
                self.condition.notify()
            except queue.Empty:
                self.condition.wait()
                print("no pwd")

                self.condition.release()

            #todo brute force algurithm implementation
            if not password is None:
                myLetters = string.ascii_letters + string.digits + string.punctuation
                for i in range(3, 5):
                    for j in map(''.join, itertools.product(myLetters,
                                                            repeat=i)):
                        if password.check(test=str(j)):
                            print("password found: " + j)
Beispiel #8
0
 def test_check1(self):
     pwd = Password("asd")
     self.assertEqual(True, pwd.check("asd"))