Beispiel #1
0
def RenamePassTitle(newPassTitle, lineNum, encryptionKey):
    AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey)
    if (not DoesProgramFileExist(passFile)):
        return False

    #Get Current File
    with open((GetFileLocation() + passFile), "r") as f:
        data = f.readline()
    fileContent = Encryptor.DecryptFile(data, AESEncryptionKey)

    if (lineNum < 0 or lineNum >= len(fileContent)):
        return False

    #Get password locker line
    fullLine = SplitString(fileContent[lineNum], sep2)

    lineToWrite = fullLine[0] + sep2 + Encryptor.AESEncrypt(
        newPassTitle, AESEncryptionKey) + sep2 + fullLine[2]

    #Write back to file
    fileContent[lineNum] = lineToWrite

    writeFileString = Encryptor.EncryptFile(fileContent, AESEncryptionKey)
    with open((GetFileLocation() + passFile), "w") as f:
        f.write(writeFileString)

    return True
Beispiel #2
0
def DeletePassword(passIndex, encryptionKey):
    AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey)
    #Read all from file
    if (not DoesProgramFileExist(passFile)):
        return None
    with open((GetFileLocation() + passFile), "r") as f:
        encDataSet = f.readline()
    data = Encryptor.DecryptFile(encDataSet, AESEncryptionKey)
    #Remove unwanted password
    del data[passIndex]
    try:
        #Re-write file
        encDataSet = Encryptor.EncryptFile(data, AESEncryptionKey)
        with open((GetFileLocation() + passFile), "w") as f:
            f.write(encDataSet)
        return True
    except:
        return False
Beispiel #3
0
def AmmendPasswordFile(passTitle,
                       password,
                       encryptionKey,
                       inputUsername="******",
                       inputExtra="null",
                       inputGroup="null",
                       lineNum=-1):
    AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey)
    #Returns successful runs,
    if (not DoesProgramFileExist(passFile)):
        #Will create the file if it doesn't exist
        toWrite = ["#Locker.psl"]
        encryptedLineWrite = Encryptor.EncryptFile(toWrite, AESEncryptionKey)
        with open((GetFileLocation() + passFile), "w+") as pF:
            pF.write(encryptedLineWrite)

    #Get Current File
    with open((GetFileLocation() + passFile), "r") as f:
        data = f.readline()
    fileContent = Encryptor.DecryptFile(data, AESEncryptionKey)

    #lineNum = -1 denotes a new password to be added
    if (lineNum >= 0 and lineNum < len(fileContent)
            and (password == "" or inputUsername == "" or inputGroup == ""
                 or inputExtra == "")):
        #Check what values = '' and overrite with stored data
        #First seperate fileContent by sep2
        sep2Content = SplitString(fileContent[lineNum], sep2)
        #Now update group values
        if (inputGroup == ""):
            inputGroup = sep2Content[0]
        #Now get user/pass segment
        userPassSeg = Encryptor.AESDecrypt(sep2Content[2],
                                           AESEncryptionKey).split(userpassSep)
        if (password == ""):
            password = userPassSeg[0]
        if (inputUsername == ""):
            inputUsername = userPassSeg[1]
        if (inputExtra == ""):
            inputExtra = userPassSeg[2]
            print(inputExtra)

    lineWrite = inputGroup + sep2 + Encryptor.AESEncrypt(
        passTitle, AESEncryptionKey) + sep2 + Encryptor.AESEncrypt(
            password + userpassSep + inputUsername + userpassSep + inputExtra,
            AESEncryptionKey)

    #Ammend file contents
    if (lineNum == -1):
        fileContent.append(lineWrite)
    elif (lineNum >= 0):
        if (lineNum > len(fileContent)):
            return False
        fileContent[lineNum] = lineWrite
    else:
        raise ValueError("Invalid edit number, use '-1' to add new password")

    #Write back to file
    writeFileString = Encryptor.EncryptFile(fileContent, AESEncryptionKey)
    with open((GetFileLocation() + passFile), "w") as f:
        f.write(writeFileString)

    return True