def cmp(): print("Changing master password. Press ctrl+c to cancel") global conn, acc_pswd try: pswd = hidepass.getpass(prompt="Enter current master password: "******"\n!!Cancelled!!") return 0 hash_pswd = (hashlib.md5( (pswd + "314159265358979323846264338327").encode())).hexdigest() if (hash_pswd != acc_pswd): print("!! Wrong password !!") pass else: while (True): try: mst_pswd = hidepass.getpass( prompt="\nEnter new master password : "******"re-enter new master password: "******"\n!!Cancelled!!") return 0 if (mst_pswd == rem_pswd): hash_pswd = (hashlib.md5( (mst_pswd + "314159265358979323846264338327").encode())).hexdigest() conn.execute("update app_det set pswd = '" + hash_pswd + "'") conn.commit() print("\nMaster password updated\n") startup() break else: print("!Password Mismatch!\n\n")
def cpwd(): try: pwd = hidepass.getpass(prompt=Fore.YELLOW + "Enter your current client manager password: "******"SELECT pw from userData") for d in data: if (d[0] == md5hash(pwd + "saltLAKE")): pass else: print(Fore.RED + "Wrong Password!!") return while (True): pswd = hidepass.getpass( prompt=Fore.YELLOW + "Enter your new client manager password : "******"Confirm your new client manager password: "******"Password confirmation mismatch!!") continue conn.execute("update userData set pw = '" + md5hash(pswd + "saltLAKE") + "'") conn.commit() print(Fore.GREEN + "Password updated successfully") except KeyboardInterrupt: print() return
def ent(): global conn try: print( "\nCreate new entry. (press ctrl+c to cancel, leave blank if something is not applicable)\n" ) def_pass = genrand() stnm = str(input("Enter site/app name : ")) mlid = str(input("Enter mail id used : ")) usnm = str(input("Enter user name used: ")) pswd = hidepass.getpass( prompt="Enter/Create your password (suggested: '" + def_pass + "', leave blank to use suggetion) : ") if (pswd.replace(" ", "") == ""): pswd = def_pass elif (stnm.replace(" ", "") == ""): stnm = " " elif (mlid.replace(" ", "") == ""): mlid = " " elif (usnm.replace(" ", "") == ""): usnm = " " pswd = str(encr(pswd)) conn.execute("INSERT INTO pwd_det (site,mail,uname,pswd) VALUES ('" + stnm + "','" + mlid + "','" + usnm + "','" + pswd + "')") conn.commit() pswd = decr(pswd) t = Texttable() t.set_cols_align(['c', 'c', 'c', 'c']) print("\nData created \n") t.add_rows([['Site/App name', 'Mail ID', 'Username', 'Password'], [stnm, mlid, usnm, pswd]]) print(t.draw()) except (KeyboardInterrupt): print("\n!!Cancelled!!\n")
def reset(): global homePath try: print( Fore.GREEN + "\nAre you sure you wanna logout from this device?? (Press ctrl+c to cancel)" ) pwd = hidepass.getpass(prompt=Fore.YELLOW + "Enter your client manager password: "******"SELECT pw from userData") for d in data: if (d[0] == md5hash(pwd + "saltLAKE")): remove(homePath + "/.main.db") print(Fore.GREEN + "Successfully logged out!!") exit() else: print(Fore.RED + "Wrong Password!!") return except KeyboardInterrupt: print() return ()
def reset(): global acc_pswd, dbPath print( "WARNING!! YOU WON'T BE ABLE TO RECOVER ANY PASSWORD AFTER YOU RESET!!" ) try: mst_pswd = hidepass.getpass( prompt= "Type master password for confirmation (press ctrl-c to cancel): ") except (KeyboardInterrupt): print("\n!!Cancelled!!") return 0 hash_pswd = (hashlib.md5( (mst_pswd + "314159265358979323846264338327").encode())).hexdigest() if (hash_pswd != acc_pswd): print("!! Wrong password !!") return 0 os.remove(dbPath + '.pswds.db') print("!!DELETED!!") sleep(3) os.system("clear") exit()
def dlt(txt): global conn, acc_pswd avlb = False try: id = int(txt[4:len(txt)]) except: print("Missing or Invalid operand") return 0 id = str(id) cur = conn.execute("select * from pwd_det where siteId = " + id + ";") for i in cur: avlb = True stid, stnm, mlid, usnm, pswd = i[0], i[1], i[2], i[3], decr(i[4]) if (avlb == False): print("No data found regarding Entry ID " + id + ". Try using see command to check for available Entry ID's.") return 0 print("Are you sure you want to delete this?") t = Texttable() t.set_cols_align(['c', 'c', 'c', 'c', 'c']) t.add_rows( [['Site ID', 'Site/App name', 'Mail ID', 'Username', 'Password'], [stid, stnm, mlid, usnm, pswd]]) print(t.draw()) try: mst_pswd = hidepass.getpass( prompt= "Type master password for confirmation (press ctrl-c to cancel): ") except (KeyboardInterrupt): print("\n!!Cancelled!!") return 0 hash_pswd = (hashlib.md5( (mst_pswd + "314159265358979323846264338327").encode())).hexdigest() if (hash_pswd != acc_pswd): print("!! Wrong password !!") return 0 conn.execute("delete from pwd_det where siteId = " + id) conn.commit() print("\nData Deleted")
def storeRetrivePass(dir): global conn, mstrPswd devName = dir print( len("Device selected: ") * " " + Fore.YELLOW + (len(devName) + 2) * "-") print(Fore.WHITE + "Device selected: " + Fore.YELLOW + "| " + Fore.GREEN + devName + Style.RESET_ALL + Fore.YELLOW + " |") print( len("Device selected: ") * " " + Fore.YELLOW + (len(devName) + 2) * "-") dir = os.path.join(basePath, devName) print(Fore.YELLOW + "\nLooking if a password file exists....") print() if (os.path.exists(dir + "/.seKeyYourPasses.db")): print(Fore.GREEN + "File found") conn = sqlite3.connect(dir + "/.seKeyYourPasses.db") datab = conn.execute('select * from userInfo') for i in datab: if (i[1] != sha256Hash(compKey + "HOHAHA131346647979")): print( Fore.RED + Back.WHITE + " This device was not programmed from this computer, hence you can't access it. \n ( Either this is not the computer or you have deleted some important files ) " + Style.RESET_ALL) logToDB( "Someone attempted to retrieve passwords from another computer" ) exit(1) while (True): try: mstrPswd = hidepass.getpass(prompt=Fore.CYAN + "Enter master password : "******"saltyLakeBOIS@314159265") != i[0]): print(Fore.RED + Back.WHITE + " Incorrect password !! Try again " + Style.RESET_ALL) logToDB("Someone entered an incorrect password") continue break except: print("\n!! CANCELLED !!") if (len(listMedia) == 1): exit(1) return else: print(Fore.RED + "File not found") print(Fore.GREEN + "Creating new one....\n") try: while (True): mstrPswd = hidepass.getpass(prompt=Fore.CYAN + "Enter a master password : "******" ", "")) < 8): print( Fore.RED + Back.WHITE + " Please enter a valid password!! (min 8 characters) " + Style.RESET_ALL) continue confPswd = hidepass.getpass(prompt=Fore.CYAN + "Confirm the master password: "******" Password confirmation mismatch " + Style.RESET_ALL) continue break except KeyboardInterrupt: print("\n!! CANCELLED !!") if (len(listMedia) == 1): exit(1) return conn = sqlite3.connect(dir + "/.seKeyYourPasses.db") conn.execute(""" CREATE TABLE userInfo( mstrpswd text, cmptrUId text ) """) conn.execute(""" CREATE TABLE appLogs( logId integer PRIMARY KEY AUTOINCREMENT NOT NULL, desc TEXT, dateTime TEXT ) """) conn.execute(""" CREATE TABLE pswdData( pswdId integer PRIMARY KEY AUTOINCREMENT NOT NULL, site text, mail text, pswd text ) """) try: logToDB("Database created") except Exception as e: print(e) exit() conn.execute("insert into userInfo values('" + sha256Hash(mstrPswd + "saltyLakeBOIS@314159265") + "','" + sha256Hash(compKey + "HOHAHA131346647979") + "')") conn.commit() sleep(0.5) os.system("clear") print(Fore.CYAN + figlet_format("SeKeyYour", font="univers", width=1000), end="\r") print(key + Style.RESET_ALL) print( "Press ctrl+c to exit or cancel, type \\h for help and \\a for abouts") print( len("Device selected: ") * " " + Fore.YELLOW + (len(devName) + 2) * "-") print(Fore.WHITE + "Device selected: " + Fore.YELLOW + "| " + Fore.GREEN + devName + Style.RESET_ALL + Fore.YELLOW + " |") print( len("Device selected: ") * " " + Fore.YELLOW + (len(devName) + 2) * "-") while (True): try: inp = input(Fore.YELLOW + "sekeyyour/" + devName.lower().replace(" ", "_") + ":$ " + Fore.WHITE) if (inp.replace(" ", "") == "exit"): print("!! EXITED !!") if (len(listMedia) == 1): exit(1) return elif (inp == "logs"): logs = conn.execute("select * from appLogs") t = Texttable() t.set_cols_align(['c', 'c', 'c']) for i in logs: t.add_rows([['Date', 'Time', 'Description'], [i[2].split("|")[0], i[2].split("|")[1], i[1]]]) pass if (t.draw() == None): print("No activities recorded yet!") continue print(t.draw()) elif (inp[:3] == "see"): t = Texttable() t.set_cols_align(['c', 'c', 'c', 'c']) if (inp[4:] == "all" or inp[3:] == ""): logs = conn.execute("select * from pswdData") elif (inp[4:7] == "id "): try: int(inp[7:]) except: print(Fore.RED + Back.WHITE + " Please enter an integer as an argument " + Style.RESET_ALL) continue logs = conn.execute( "select * from pswdData where pswdId = " + inp[7:]) elif (inp[4:9] == "site "): logs = conn.execute( "select * from pswdData where site = '" + encryptText(inp[9:].strip(), sha256Hash(compKey + "\b" + mstrPswd)) + "'") elif (inp[4:9] == "usrn "): logs = conn.execute( "select * from pswdData where mail = '" + encryptText(inp[9:].strip(), sha256Hash(compKey + "\b" + mstrPswd)) + "'") else: print(Fore.RED + Back.WHITE + " Please enter a valid argument " + Style.RESET_ALL) continue for i in logs: pswd = decryptText(i[3], sha256Hash(compKey + "\b" + mstrPswd)) if (inp.strip() == "see"): pswd = "*" * 8 t.add_rows([ ["ID", "Site Name", "Email/Username", "Password"], [ i[0], decryptText(i[1], sha256Hash(compKey + "\b" + mstrPswd)), decryptText(i[2], sha256Hash(compKey + "\b" + mstrPswd)), pswd ] ]) if (t.draw() == None): print(Fore.RED + Back.WHITE + " Nothing found :-( " + Style.RESET_ALL) continue print(t.draw()) elif (inp == "ent"): try: while (1): site = input(Fore.CYAN + "Enter site/app name : " + Fore.WHITE) if (len(site.strip()) == 0): print(Fore.RED + Back.WHITE + " Please enter a valid site/app name " + Style.RESET_ALL) continue break usrn = input( Fore.CYAN + "Enter username/email address (leave blank if not applicable) : " + Fore.WHITE) while (1): pswd = input(Fore.CYAN + "Enter password : "******" Please enter a valid password!!" + Style.RESET_ALL) continue break conn.execute( "insert into pswdData (site,mail,pswd) values ('" + encryptText(site, sha256Hash(compKey + "\b" + mstrPswd)) + "','" + encryptText(usrn, sha256Hash(compKey + "\b" + mstrPswd)) + "','" + encryptText(pswd, sha256Hash(compKey + "\b" + mstrPswd)) + "')") conn.commit() print(Fore.GREEN + "Entry successful") logToDB("New entry made") except KeyboardInterrupt: print("\n!! CANCELLED !!") elif (inp[:3] == "dlt"): try: int(inp[4:]) except: print(Fore.RED + Back.WHITE + " Please enter an integer as an argument " + Style.RESET_ALL) continue try: t = Texttable() t.set_cols_align(['c', 'c', 'c', 'c']) for i in conn.execute( "select * from pswdData where pswdId = " + inp[4:]): t.add_rows( [["ID", "Site Name", "Email/Username", "Password"], [ i[0], decryptText( i[1], sha256Hash(compKey + "\b" + mstrPswd)), decryptText( i[2], sha256Hash(compKey + "\b" + mstrPswd)), decryptText( i[3], sha256Hash(compKey + "\b" + mstrPswd)) ]]) if (t.draw() == None): print(Fore.RED + Back.WHITE + " Nothing found :-( " + Style.RESET_ALL) continue print("Delete the following entry?") print(t.draw()) verifKey = genRandVerif() q = input("Type the following for confirmation ( " + verifKey + " ): ") if (q == verifKey): conn.execute("delete from pswdData where pswdId = " + inp[4:]) conn.commit() print(Fore.GREEN + "Entry deleted successfully") logToDB("Entry deleted") continue print("!!CANCELLED!!") except KeyboardInterrupt: print("\n!!CANCELLED!!") elif (inp[:4] == "updt"): try: int(inp[5:]) except: print(Fore.RED + Back.WHITE + " Please enter an integer as an argument " + Style.RESET_ALL) continue try: t = Texttable() t.set_cols_align(['c', 'c', 'c', 'c']) for i in conn.execute( "select * from pswdData where pswdId = " + inp[5:]): t.add_rows( [["ID", "Site Name", "Email/Username", "Password"], [ i[0], decryptText( i[1], sha256Hash(compKey + "\b" + mstrPswd)), decryptText( i[2], sha256Hash(compKey + "\b" + mstrPswd)), decryptText( i[3], sha256Hash(compKey + "\b" + mstrPswd)) ]]) if (t.draw() == None): print(Fore.RED + Back.WHITE + " Nothing found :-( " + Style.RESET_ALL) continue print("Update the following entry?") print(t.draw()) q = input("(Y)es/(N)o: ") if (q.lower() == "y"): print("\nLeave blank if not to be changed") qId = str(i[0]) site = decryptText( i[1], sha256Hash(compKey + "\b" + mstrPswd)) usrn = decryptText( i[2], sha256Hash(compKey + "\b" + mstrPswd)) pswd = decryptText( i[3], sha256Hash(compKey + "\b" + mstrPswd)) updt_site = input( Fore.CYAN + "Enter new site/app name (currently '" + site + "'): " + Fore.WHITE) updt_usrn = input( Fore.CYAN + "Enter new username/mail id (currently '" + usrn + "')(leave an asteriks(*) if making it blank): " + Fore.WHITE) updt_pswd = input(Fore.CYAN + "Enter new password (currently '" + pswd + "'): " + Fore.WHITE) if (updt_site.strip() == ""): updt_site = site if (updt_pswd.strip() == ""): updt_pswd = pswd if (updt_usrn.strip() == ""): updt_usrn = usrn elif (updt_usrn.strip() == "*"): updt_usrn = "" conn.execute( "update pswdData set site='" + encryptText( updt_site, sha256Hash(compKey + "\b" + mstrPswd)) + "', mail='" + encryptText( updt_usrn, sha256Hash(compKey + "\b" + mstrPswd)) + "', pswd = '" + encryptText( updt_pswd, sha256Hash(compKey + "\b" + mstrPswd)) + "' where pswdId = " + qId) conn.commit() logToDB("An entry was updated") continue print("!!CANCELLED!!") except KeyboardInterrupt: print("\n!!CANCELLED!!") elif (inp[:3] == "cpy"): try: int(inp[4:]) except: print(Fore.RED + Back.WHITE + " Please enter an integer as an argument " + Style.RESET_ALL) continue for i in conn.execute( "select * from pswdData where pswdId = " + str(inp[4:])): copy( decryptText(i[3], sha256Hash(compKey + "\b" + mstrPswd))) print(Fore.GREEN + "Password copied for site/app name " + decryptText(i[1], sha256Hash(compKey + "\b" + mstrPswd)), end="") if (i[2] != ""): print(" and username/mail id " + decryptText( i[2], sha256Hash(compKey + "\b" + mstrPswd)), end="") print(" successfully") elif (inp == "xlog"): conn.execute("delete from appLogs") conn.commit() print(Fore.GREEN + "All logs deleted successfully") elif (inp == "clear"): os.system("clear") elif (inp == "cmp"): try: mPswd = hidepass.getpass( prompt=Fore.CYAN + "Enter current master password: "******"Enter new master password : "******" Please enter a valid password (min 8 characters) " + Style.RESET_ALL) continue cPswd = hidepass.getpass( prompt=Fore.CYAN + "Confirm new master password : "******" Password confirmation mismatch " + Style.RESET_ALL) continue break print("Wait!! Do not quit the program.....") for i in conn.execute("select * from pswdData"): qId = str(i[0]) site = decryptText( i[1], sha256Hash(compKey + "\b" + mPswd)) usrn = decryptText( i[2], sha256Hash(compKey + "\b" + mPswd)) pswd = decryptText( i[3], sha256Hash(compKey + "\b" + mPswd)) conn.execute( "update pswdData set site='" + encryptText( site, sha256Hash(compKey + "\b" + nPswd)) + "',mail='" + encryptText( usrn, sha256Hash(compKey + "\b" + nPswd)) + "',pswd='" + encryptText( pswd, sha256Hash(compKey + "\b" + nPswd)) + "' where pswdId = " + qId) conn.commit() conn.execute("update userInfo set mstrpswd = '" + sha256Hash(nPswd + "saltyLakeBOIS@314159265") + "'") conn.commit() print(Fore.GREEN + "Password changed successfully") logToDB("Password changed") mstrPswd = nPswd else: print(Fore.RED + Back.WHITE + " Incorrect password " + Style.RESET_ALL) continue except KeyboardInterrupt: print("\n!!CANCELLED!!") elif (inp == "reset"): print("Reset the application !?") mPswd = hidepass.getpass( prompt=Fore.CYAN + "Enter master password for confirmation: " + Fore.WHITE) if (mPswd == mstrPswd): os.system("rm " + dir + "/.seKeyYourPasses.db") print( Fore.GREEN + "\nDatabase deleted and all entries cleared successfully !!\n" ) print(Fore.CYAN + figlet_format("GoodBye!", font="nancyj", width=1000), end="\r") exit(1) else: print(Fore.RED + Back.WHITE + " Incorrect password " + Style.RESET_ALL) elif (inp == "\\h"): print("""\n|HELP| -> clear - clear screen -> exit - exits the program -> logs - display application usage logs -> ent - make an entry to the password manager -> see - displays passwords along with site name and username/email, use it as follows: (*) see - show all entries but blocking the password (*) see all - shows all the entries (*) see id <query id> - shows entry corresponding to the id (*) see site <site name> - shows all entries corresponding to the site name (*) see usrn <username name> - shows all entries corresponding to the username/email id -> dlt - deletes an entry with the corresponding id, use it as follows: (*) dlt <query id> -> cpy - copy the password from entry with the corresponding id, use it as follows: (*) cpy <query id> -> updt - updates an entry with the corresponding id, use it as follows: (*) updt <query id> -> cmp - change master password -> xlog - deletes all the application usage logs -> reset - resets the whole application (deletes all the entries and logs and clears the master password too) ⚠ use with caution -> \\h - help -> \\a - about\n """ + Fore.CYAN + "get <query id> via 'see' command\n") elif (inp == "\\a"): print( """\n|ABOUT|\n\tThis is a CLI, python based external device password manager created by Rhiddhi Prasad Das.\n\tYou can use this software to securely store all your passwords on an external device\n\tthat can only be accessed by the computer the database was created by.\n Github : https://github.com/rpd-512/ Twitter: https://twitter.com/RhiddhiD Fiverr : https://www.fiverr.com/rpd_512 Email : [email protected]\n""") except KeyboardInterrupt: print("\n!! EXITED !!") if (len(listMedia) == 1): exit(1) return
def authClient(): global conn, homePath, name, mainUserId homePath = "/home/" + popen("whoami").read().replace("\n", "") + "/.backJack" if (not path.exists(homePath + "/.main.db")): print(Fore.CYAN + figlet_format("BackJack Login")) print(Fore.YELLOW + "If you don't have an account, please make one here: ", end="") print(Fore.CYAN + siteName) print("Press ctrl+c to exit\n") while (True): try: user = input(Fore.CYAN + 'Enter your backjack username : '******'user': user, 'pswd': pswd }) except: print(Fore.RED + "Internet connection not found!!") exit() auth = int(resp.text) if (not bool(auth)): print(Fore.RED + "\nIncorrect/Invalid password or username.\n") continue else: print(Fore.GREEN + "Found your account :-) !!\n") while (1): pswd = hidepass.getpass( prompt=Fore.CYAN + "Enter a password for client manager : " + Fore.WHITE) cpwd = hidepass.getpass(prompt=Fore.CYAN + "Confirm your password : "******"Use a stronger password (longer than 8 digits)" ) else: print(Fore.RED + "Password confirmation mismatch!!") try: mkdir(homePath) except: pass conn = sqlite3.connect(homePath + "/.main.db") conn.execute("""CREATE TABLE userData( id text, pw text, rv integer )""") conn.execute("""CREATE TABLE cmndData( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, cmnd text, date text, time text )""") conn.execute("insert into userData (id,pw,rv) values('" + md5hash(str(auth) + "saltLAKE") + "','" + md5hash(str(pswd) + "saltLAKE") + "',1)") conn.commit() print(Fore.GREEN + "Successfully logged in!!\n") break except KeyboardInterrupt: print() exit() else: conn = sqlite3.connect(homePath + "/.main.db") data = conn.execute("SELECT * FROM userData") for i in data: appData = i resp = post(siteName + "authAPI.php", {'authid': appData[0]}) r = int(resp.text) if (not r): for i in listdir(homePath): remove(homePath + '/' + i) rmdir(homePath) exit() resp = post(siteName + "authAPI.php", {'authid': i[0], 'giveInfo': ''}) userData = json.loads(str(resp.text)) name = userData['name'] while (True): pswd = hidepass.getpass(prompt=Fore.GREEN + "Enter client manager password: "******"saltLAKE") == i[1]): welcome() break else: print(Fore.RED + "Wrong Password!!")
def startup(): global dbPath, clrScr, acc_pswd if (os.name == "nt"): clrScr = "cls" dbPath = "" else: clrScr = "clear" dbPath = os.path.expanduser("~") + "/.pswd_mngr/" if (os.path.exists(dbPath + ".pswds.db")): conn = sqlite3.connect(dbPath + ".pswds.db") datab = conn.execute('select * from app_det;') for i in datab: acc_pswd = i[0] while (True): try: pswd = hidepass.getpass(prompt="Enter master password: "******"\n!!Cancelled!!") sleep(3) exit() hash_pswd = (hashlib.md5( (pswd + "314159265358979323846264338327").encode())).hexdigest() if (hash_pswd != acc_pswd): print("!! Wrong password !!") sleep(3) exit() else: os.system(clrScr) print("Type \"\\h\" for help, \"\\a\" for about") break else: print("\nWelcome to your very own password manager!!") while (True): try: mst_pswd = hidepass.getpass( prompt="Please create your master password : "******"Please re-enter your master password: "******"\n!!Cancelled!!") sleep(3) exit() if (mst_pswd == rem_pswd): try: os.mkdir(dbPath) except: pass conn = sqlite3.connect(dbPath + ".pswds.db") conn.execute("create table app_det (pswd text);") conn.execute("""create table pwd_det ( siteId integer PRIMARY KEY AUTOINCREMENT NOT NULL, site text, mail text, uname text, pswd text );""") hash_pswd = (hashlib.md5( (mst_pswd + "314159265358979323846264338327").encode())).hexdigest() execdb = "insert into app_det (pswd) values ('" + hash_pswd + "');" conn.execute(execdb) conn.commit() conn.close() print("Congrats!! Master Password is set! Lets Get started!") sleep(3) os.system(clrScr) startup() break else: print("!Password Mismatch!\n\n")