def deleteAll(): if d.writeData(""): f.Log("Deleted all accounts.", "deleteAll") refreshWindow() else: f.Log("Could not delete all accounts. Must've logged it above.", "deleteAll")
def deleteAccount(id): accounts = readData() if accounts == "error": return False else: if accounts == "": f.Log("No account(s) to delete.", "deleteAccount") return False else: accounts.pop(id,None) writeData(f.DICTtoJSON(accounts)) f.Log("Account deleted: " + id, "deleteAccount") return True
def checkPassword(pwd): try: with open("bin/gp.txt", "r", encoding='utf-8') as gpfile: contents = decrypt(gpfile.read()) data = f.JSONtoDict(contents) if encrypt(pwd) == data["p"]: return True else: f.Log("Bad Global", "checkPassword") return False except IOError as e: f.Log(e, "checkPassword") return False
def unlockSession(): global unlocked pwd = simpledialog.askstring("Unlock Session", "If you unlock this session, you will not be asked to enter a password\neach time you want to decrypt an account's information.\nUse when safe.\n\nEnter your global password to continue.", show='*') if pwd is not None: if ap.checkPassword(pwd) == True: unlocked = True f.Log("This session has been unlocked.", "unlockSession") refreshWindow() else: f.Log("This session couldn't unlocked.", "unlockSession") messagebox.showerror("Error", "Wrong Password. (or error)")
def storeGlobal(pwd): saltfile = open("bin/gp.txt", "w+", encoding='utf-8') dict1 = {"p": pwd} contents = json.dumps(dict1) saltfile.write(encrypt(str(contents))) saltfile.close() f.Log("GPwd stored", "storeGlobal")
def countAccounts(): try: with open(data_path, "r", encoding='utf-8') as datafile: contents = datafile.read() if contents == "": f.Log("No accounts found on startup", "countAccounts") datafile.close() return 0 else: contents = f.JSONtoDict(ap.decrypt(contents)) count=len(contents) f.Log("Found "+str(count)+" account(s) on startup","countAccounts") datafile.close() return count except IOError as e: f.Log(e, "moreThanOne") return -1
def genSalt(): diff = int(random.randrange(0, 10)) opps = ["+", "-"] secure_random = random.SystemRandom() opp = secure_random.choice(opps) final = str(diff) + opp saltfile = open("res/s.txt", "w+") saltfile.write(final) saltfile.close() f.Log("Salt created", "genSalt")
def writeData(contents): try: with open(data_path, "w+", encoding='utf-8') as file: file.write(ap.encrypt(str(contents))) file.close() return True except IOError as e: f.Log(e, "writeData") return False
def encrypt(pwd): pwdls = list(pwd) pwd = "" al = "" l = "" for i in range(0, len(pwdls)): diff = int(random.randrange(0, 10)) pwd += str(ord(pwdls[i]) + diff) al += str(diff) l += str(len(str(ord(pwdls[i]) + diff))) f.Log("Encrypt password request.", "encrypt[al]") return pwd + "x" + al + "x" + l
def readData(): try: with open(data_path, "r", encoding='utf-8') as datafile: contents = datafile.read() if contents != "": contents = f.JSONtoDict(ap.decrypt(contents)) datafile.close() return contents except IOError as e: f.Log(e, "readData") return "error"
def readSalt(): global difference global operator try: with open("res/s.txt", "r", encoding='utf-8') as saltfile: contents = saltfile.read() operator = contents.strip()[-1] difference = int(contents[:-1]) saltfile.close() return True except IOError as e: f.Log(e, "readSalt") return False
def addEntry(name,uname,pwd): accounts = readData() pwd = al.encrypt(pwd) entry = {"n":name,"u":uname,"p":pwd} if accounts == "error": return False else: if accounts == "": writeData(f.DICTtoJSON({countAccounts() + 1: entry})) else: accounts.update({str(countAccounts() + 1): entry}) writeData(f.DICTtoJSON(accounts)) f.Log("New account added: "+name,"addEntry") return True
def decrypt(pwd): code = pwd.split("x") a = 0 # Start of split b = 0 # End of Split c = list(code[2]) # Split by how much? d = list(code[1]) # Subtract by how much? pwd_chars = [] for i in c: letter = code[0][a:a + int(c[b])] pwd_chars.append(letter) a = a + int(c[b]) b += 1 pwd = "" for i in range(0, len(pwd_chars)): pwd += chr(int(pwd_chars[i]) - int(d[i])) f.Log("Decrypt password request.", "decrypt[al]") return pwd
def lockSession(): global unlocked unlocked = False f.Log("This session has been locked.", "lockSession") refreshWindow()
def refreshWindow(): f.Log("Window has been refreshed.", "refreshWindow") roots.destroy() showWindow()
# This is the main file for the Password Keeper Program. # Import main modules import sys sys.path.insert(0, 'res') sys.path.insert(0, 'bin') # Import app modules import f #Log the startup f.LogStartUp() # Check if the modules work or not. print( "Application started. This project was made by Aekansh Dixit (First Year Student of PES University, Bengaluru) for the Python Project Assignments of the first semester and Collaborated by Simranjot Sandhu ( HEC, Jagadhri))." ) # 0n the launch, we will check if the application was already launched or not by viewing our data fileset. # TODO: Install the res folder along with the files, and empty bin folder if (not f.checkFileExists("bin/gp.txt")): f.Log("This is the first launch.", "mainFile") import s s.showWindow() else: f.Log("Data found", "mainFile") import m m.showWindow()