def showUserStuff(self): #Here Where the user can decide if he want to see his creds or to store them into the DB or generate a secure password q = input("menu >> ") if q == "1": try: self.showCredUser() except KeyboardInterrupt: print("") self.showUserStuff() elif q == "2": try: self.generatePassword() except KeyboardInterrupt: print("") self.showUserStuff() elif q == "clear": self.get_platform() Avatar.print_avatar() self.showUserStuff() elif q == "help": print(self.help_) self.showUserStuff() else: self.showUserStuff()
def __init__(self): #Connecting with our database it's an sqlite3 db self.con = sqlite3.connect("User.db") # DB for registration and login self.cursor = self.con.cursor() # Cursor of registration and login db self.get_platform() self.progAvatar = Avatar.print_avatar() self.C = Crypt() self.G = PassGen() self.Parser = ParseArg() self.path_keys = "./keys" self.pathDir = "./main_cred_db" self.global_db = './User.db' #######Colors####### self.fore = Fore self.reset = Style.RESET_ALL self.green = self.fore.GREEN self.red = self.fore.RED self.yellow = self.fore.YELLOW
def showCredUser(self): s = input(f"{self.green}Credentials >>> {self.reset}") self.categories = ["Social", "Email", "Finance", "Shopping", "Other"] command = s.split() if s == "help".lower().strip(): print(self.green, 'Categories ===> ', ",".join([f.lower() for f in self.categories]), self.reset) print( f"{self.yellow}Enter one of the Categories above, OR " '\n', "\n", "delete --id <id> --category <category> \n", "\n", "update --category <category> --id <id> --username <username>* --password <password>* --site <site>* \n", "\n", "Note : You can Update username , password and site at once it's up to you it's optional \n" "\n", "add --username <username> --password <password> --site <site> --category <category>\n", "\n", "<help> Prints this help menu" "\n", "\n", "<clear> clears the screen" "\n", "\n", f"Ctrl+c to return back{self.reset}" "\n", ) self.showCredUser() # Show user tables # Do not touch this ^ elif s.lower().strip() in [ c.lower() for c in self.categories ]: #If the input is a category in the categories's list and it's in lower case category = s.strip() #Remove all spaces from user inputs print(self.green, f"YOU ARE IN {category} CATEGORY", self.reset) self.c.execute("SELECT ID,user,pw,site FROM '%s' " % (category)) #removing ID here data = self.c.fetchall() table_data = [[ "{}ID{}".format(self.yellow, self.reset), "{}Username{}".format(self.yellow, self.reset), "{}Password{}".format(self.yellow, self.reset), "{}Site{}".format(self.yellow, self.reset) ]] table = AsciiTable(table_data) for I, U, P, S in data: if S == None: #If there is no Site in the DB S = "-" table_data.append([I, U, P, S]) print(table.table) self.showCredUser( ) # redirect the user to the beginning of the function again elif s.lower() == "clear": self.get_platform() Avatar.print_avatar() self.showCredUser() else: self.Parser.parse_arg(command) # parse commands self.Parser.execute_Arg( self.Parser.parse_arg(command), self.deleteUserStuff, self.saveUserStuff, self.udpateUserStuff) # execute function of each command #print(self.red,f"ERROR Wrong category name ==> {s}",self.reset) self.showCredUser()
def login(self): self.userlogin = input("Username :"******"Master Password :"******"Key Path ('What is this press <w>')Default [./keys]: ") if self.Dkey == 'w': print( "PATH OF THE ENCRYPTION/DECRYPTION KEY WE HAVE GENERATED FOR YOU ONCE YOU REGISTERED FOR AN ACCOUNT!\n" ) self.login() elif self.Dkey == "": self.Dkey = self.path_keys pass else: pass try: #Load the encryption key self.k_key = self.C.load_key(self.Dkey, self.userlogin.strip()) #Ecrypt GLOBAL db self.C.decrypt("User.db.encrypted", self.global_db, self.k_key) except FileNotFoundError: print( "No Suck User registred before / your encryption key file is not in the default path" ) self.login() # TAKE THE PASSWORD AND ENCRYPT IT THEN COMPARE IT WITH THE OTHER ONE ON THE DB pswe = hashlib.sha256(bytes(passwd, ("utf-8"))) psweh = pswe.hexdigest() self.cursor.execute( "SELECT * FROM users WHERE username=? AND password=?", (self.userlogin.strip(), psweh.strip() )) # Ensure that the username and password are in our DB if self.cursor.fetchone( ) is not None: #if True i mean if username & password are in out DB show to user his stuff print(self.green, "Welcome", self.reset) #load user key self.key = self.C.load_key(self.path_keys, self.userlogin.strip( )) #Load the User key that he generate When he registred #decrypt the db find_dec = f"{self.userlogin.strip()}.db.encrypted" # Find the encrypted DB for each user dec_file = os.path.join("./main_cred_db", find_dec) #os.path.join("./main_cred_db",f"{self.userlogin}.db") # get the name of the user db after encryption end_file = self.get_user_db( self.userlogin.strip() ) #same above but instead of get in it manually i'm getting the db path from users database self.C.decrypt( dec_file, end_file, self.key ) #Decryption Function you can find the detail about this function in <symmetric.py> file self.db = end_file if self.db == None: print( f"There is no username {self.userlogin} YOU are not registred yet" ) self.getUserStuff() self.conn = sqlite3.connect(self.db) self.c = self.conn.cursor() #Show to user his Stuff ## First Screen Help ## self.help_ = (f"{self.yellow}[1]Credentials" "\n" "[2]Generate Secure password" "\n" "help show this Help menu\n" "clear clears the screen\n" f"Ctrl+ C to Exit{self.reset}" "\n") self.get_platform() Avatar.print_avatar() #Print the ascii art print(self.help_) self.showUserStuff() else: #else show logggin failed print("Failed to login") self.C.encrypt( self.global_db, self.k_key ) #If the user failed to login enrypt the global db again self.getUserStuff()
def register(self): username = input("Username : "******"Master Password : "******"Email :") reg = re.findall(r'\S+@\S+', email) #Ensure that the username is not on our DB if self.get_user(username): print(self.red, "User already used! ", self.reset) print(self.red, "Please Try again !", self.reset) self.getUserStuff() elif self.get_email(email): print(self.red, "Email already used!", self.reset) print(self.red, "Please try again !", self.reset) self.getUserStuff() elif self.get_email == [] or self.get_user == []: pass elif reg: pass else: self.get_platform() print("Not a Valid email address") print("Retry Please !") Avatar.print_avatar() self.getUserStuff() #Create a db for that particular user db_path = shutil.copy2("defaulcred.db", f"./main_cred_db/{username}.db") #Generate a symmetric key for the user self.C.generate_key(self.path_keys, username) key = self.C.load_key(self.path_keys, username) filename = db_path #encrypt the db with that generated key self.C.encrypt(filename, key) #TAKE THE PASSWORD AND ENCRYPT IT BEFORE ENTER IT TO THE DB pWe = hashlib.sha256(bytes(masterPw, ('utf-8'))) pWeH = pWe.hexdigest() #Store user stuff into DB self.cursor.execute( "INSERT INTO users (username,password,email,DBPATH) \ VALUES ('%s', '%s','%s' ,'%s')" % (username, pWeH, email, db_path)) self.con.commit() #Encrypt User.db self.C.encrypt(self.global_db, key) print(self.green, "Encrypted User.db") print( self.green, "We have generated a key for the encryption of your credentials database" ) print(self.green, "Successfully registred !", self.reset) Avatar.print_avatar() print(f"{self.yellow}Login :{self.reset}") self.login()