def login(): with open(program_accounts_dir, 'r') as f: accounts = json.load(f) loop_var = 0 while loop_var != 1: print(Fore.BLUE + 'Username > 5 chars | 0 = Exit:' + Fore.WHITE, end=' ') username = input() if username == '': print(acc_names_error) continue if username == '0': loop_var = 1 continue print(Fore.BLUE + 'Password > 5 chars:' + Fore.WHITE, end=' ') password = input() if password == '': print(passwords_error) continue print() # Prints new line if crypter.encode(username) in accounts: if accounts[crypter.encode(username)] == crypter.encode(password): print(Fore.GREEN + 'Login successful.' + Fore.WHITE) print('\n') return ['login successful', username] else: print(Fore.RED + 'Password is incorrect!' + Fore.WHITE) else: print(Fore.RED + 'Username is incorrect!' + Fore.WHITE) print('\n') # Prints 2 new lines
def remove_acc(): current_dir = os.getcwd() with open(program_accounts_dir, 'r') as f: accounts = json.load(f) loop_var = 0 while loop_var != 1: print(Fore.YELLOW + 'Username | 0 = Exit:' + Fore.WHITE, end=' ') username = input() if username == '0': loop_var = 1 continue elif username == '': print(acc_names_error) continue elif crypter.encode(username) not in accounts: print(Fore.RED + 'An account with this username does not exist, try again.' + Fore.WHITE) continue print(Fore.YELLOW + 'Password:'******' ' + Fore.WHITE) password = input() print(Fore.YELLOW + 'Password again:' + Fore.WHITE, end=' ') password_again = input() print() # Prints new line if password != password_again: print(Fore.RED + 'Passwords do not match, try again.' + Fore.WHITE) continue elif accounts[crypter.encode(username)] != crypter.encode(password): print(Fore.RED + 'Password is incorrect, try again.' + Fore.WHITE) continue print(Fore.YELLOW + 'Are you sure you want to delete account ' + username + '? (yes/no)' + Fore.WHITE, end=' ') boolean = input() print() # Prints new line if boolean == 'yes': del accounts[crypter.encode(username)] with open(program_accounts_dir, 'w') as f: json.dump(accounts, f, indent=4) os.chdir(current_dir + user_accounts_dir) dir_files = os.listdir() for each_file in dir_files: if username in each_file: os.remove(each_file) os.chdir(current_dir) print(Fore.GREEN + 'Successfully removed account ' + username + '.' + Fore.WHITE) loop_var = 1 else: print(Fore.BLUE + 'Account did not get deleted.' + Fore.WHITE) print('\n') # Prints 2 new lines
def restore(username): desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') current_dir = os.getcwd() os.chdir(desktop) backup_file_name = username + 'backup.txt' try: with open(backup_file_name, 'r') as f: backup_file = f.read() except FileNotFoundError: return 'desktop no backup.txt' os.chdir(current_dir + user_accounts_dir) dir_files = os.listdir() for each_file in dir_files: if username in each_file: os.remove(each_file) backup_file = backup_file.split('\n\n') folder_list = [] for folder in backup_file: pattern = re.compile(r'.*?(?=:)') try: folder = pattern.findall(folder)[0] except IndexError: pass if '\\n' in folder: folder = folder.replace('\\n', '') if folder == '' or folder == '\n': continue folder_list.append(folder) acc_content = [] for content in backup_file: content_index = backup_file.index(content) try: folder_name = folder_list[content_index] + ':' except IndexError: continue if folder_name in content: content = content.replace(folder_name, '') acc_content.append(content) else: continue new_acc_content = [] for iteration in acc_content: iteration = iteration.replace('\n', '') new_acc_content.append(iteration) pattern_usernames = re.compile(r'(?<=username: <).*?(?=> <--)') pattern_passwords = re.compile(r'(?<= password: <).*?(?=>,)') pattern_label = re.compile(r'(?<=label: <).*?(?=> <--> username:)') pattern_number = re.compile(r'(?<=number: <).*?(?=> <--> )') pattern_make_acc_checkable = re.compile( r'(?<=number:).*?(?= <--> password: <)') pattern_acc_number = re.compile(r'(?<= <).*?(?=> <--> label:)') username_list = '' password_list = '' label_list = '' number_list = '' acc_numbers_with_label = [] each_acc_content = '' each_acc_numbers_with_label = '' for each in new_acc_content: usernames = pattern_usernames.findall(each) passwords = pattern_passwords.findall(each) labels = pattern_label.findall(each) numbers = pattern_number.findall(each) checkable_acc = pattern_make_acc_checkable.findall(each) for each_acc in checkable_acc: if 'label:' in each_acc: acc_number = pattern_acc_number.findall(each_acc)[0] each_acc_numbers_with_label += acc_number + '&&' else: continue acc_numbers_with_label.append(each_acc_numbers_with_label) for each_username in usernames: username_list += '%<' + each_username + '>%' for password in passwords: password_list += '!<' + password + '>!' for label in labels: label_list += '#<' + label + '>#' for number in numbers: number_list += '}<' + number + '>}!' each_acc_content += number_list + username_list + password_list + label_list + '&&' username_list = '' password_list = '' label_list = '' number_list = '' each_acc_numbers_with_label = '' each_acc_content = each_acc_content.split('&&') new_usernames_pattern = re.compile(r'(?<=%<).*?(?=>%)') new_passwords_pattern = re.compile(r'(?<=!<).*?(?=>!)') new_labels_pattern = re.compile(r'(?<=#<).*?(?=>#)') new_numbers_pattern = re.compile(r'(?<=}<).*?(?=>})') i = 0 for full_acc in each_acc_content: new_usernames = new_usernames_pattern.findall(full_acc) new_passwords = new_passwords_pattern.findall(full_acc) new_labels = new_labels_pattern.findall(full_acc) new_numbers = new_numbers_pattern.findall(full_acc) try: file_name = folder_list[i] + username + '.json' except IndexError: break with open(file_name, 'w') as f: f.write('{}') with open(file_name, 'r') as f: accounts = json.load(f) acc_numbers_for_label = acc_numbers_with_label[i].split('&&') x, y, z = 0, 0, 0 for item in new_usernames: if new_numbers[y] in acc_numbers_for_label: accounts[crypter.encode(new_numbers[y] + './//|||///' + item)] = crypter.encode( new_labels[z] + '///\\' + new_passwords[x]) x += 1 y += 1 z += 1 else: accounts[crypter.encode(new_numbers[y] + './//|||///' + item)] = crypter.encode( new_passwords[x]) x += 1 y += 1 with open(file_name, 'w') as f: json.dump(accounts, f, indent=4) i += 1 os.chdir(current_dir)
def remove_acc_in_folder(user): current_dir = os.getcwd() os.chdir(current_dir + user_accounts_dir) loop_var = 0 while loop_var != 1: print(Fore.BLUE + 'Folder to remove acc in | 0 = Exit:' + Fore.WHITE, end=' ') folder = input() if folder == '0': loop_var = 1 continue elif folder == '': print(acc_folder_names_error) continue file_name = folder + user + file_extension if file_name not in str(os.listdir()): print(folder_not_found) continue with open(file_name, 'r') as f: accounts = json.load(f) print(Fore.BLUE + 'Account\'s number:' + Fore.WHITE, end=' ') number = input() print(Fore.BLUE + 'Account\'s username:'******' ') account = input() if crypter.encode(account) not in accounts: print(Fore.RED + 'An account with username ' + account + ' was not found, try again.' + Fore.WHITE) print(Fore.BLUE + 'Are you sure you want to delete account' + account + '? (yes/no):', end=' ') boolean = input() print() # Prints new line if boolean == 'yes': account = crypter.encode(number + './//|||///' + account) if account not in accounts: os.chdir(current_dir) print(Fore.RED + 'Account ' + account + ' with number ' + number + ' was not found!' + Fore.WHITE) loop_var = 1 else: del accounts[account] digit = 1 new_accounts = {} for username, password in accounts.items(): current_username = crypter.decode(username).split('.')[1] if digit == 1: new_username = str( digit) + './//|||///' + current_username digit = 2 elif digit >= 2: new_username = str( digit) + './//|||///' + current_username digit += 1 new_accounts[crypter.encode(new_username)] = password with open(file_name, 'w') as f: json.dump(new_accounts, f, indent=4) os.chdir(current_dir) print(Fore.GREEN + 'Removed acc ' + account + ' in acc folder ' + folder + '.' + Fore.WHITE) loop_var = 1 else: loop_var = 1 os.chdir(current_dir) print('\n') # Prints 2 new lines
def add_acc_to_folder(user): current_dir = os.getcwd() os.chdir(current_dir + user_accounts_dir) loop_var = 0 while loop_var != 1: print(Fore.YELLOW + 'Folder to add account to | 0 = Exit:' + Fore.WHITE, end=' ') folder = input() if folder == '0': loop_var = 1 continue elif folder == '': print(acc_folder_names_error) continue file_name = folder + user + file_extension if file_name not in str(os.listdir()): print(folder_not_found) continue print(Fore.BLUE + 'Label for account (0 = None):' + Fore.WHITE, end=' ') label = input() print(Fore.BLUE + 'Username/email for the account:' + Fore.WHITE, end=' ') acc_username = input() print(Fore.BLUE + 'Password for the account:' + Fore.WHITE, end=' ') acc_password = input() print(Fore.BLUE + 'Type password again' + Fore.WHITE, end=' ') acc_password_again = input() print() # Prints new line if acc_password != acc_password_again: print(Fore.RED + 'Passwords do not match, try again.' + Fore.WHITE) continue else: if label != '0': with open(file_name, 'r') as f: accounts = json.load(f) try: last_digit = crypter.decode(list(accounts.items())[-1][0]) digit = int(last_digit.split('.///|||///')[0]) + 1 except: digit = 1 accounts[crypter.encode( str(digit) + './//|||///' + acc_username)] = crypter.encode(label + '///\\' + acc_password) with open(file_name, 'w') as f: json.dump(accounts, f, indent=4) print(Fore.GREEN + 'Added acc ' + acc_username + ' to acc folder ' + folder + '.' + Fore.WHITE) loop_var = 1 else: with open(file_name, 'r') as f: accounts = json.load(f) try: last_digit = crypter.decode(list(accounts.items())[-1][0]) digit = int(last_digit.split('.///|||///')[0]) + 1 except: digit = 1 accounts[crypter.encode( str(digit) + './//|||///' + acc_username)] = crypter.encode(acc_password) with open(file_name, 'w') as f: json.dump(accounts, f, indent=4) print(Fore.GREEN + 'Added acc ' + acc_username + ' to acc folder ' + folder + '.' + Fore.WHITE) loop_var = 1 os.chdir(current_dir) print('\n') # Prints 2 new lines
def register_acc(): with open(program_accounts_dir, 'r') as f: accounts = json.load(f) loop_var = 0 while loop_var != 1: print(Fore.BLUE + 'New username > 4 chars | 0 = Exit:' + Fore.WHITE, end=' ') username = input() if username == '0': loop_var = 1 continue elif username == '': print( Fore.RED + 'Username can not be empty, try again with a different username.' + Fore.WHITE) continue elif crypter.encode(username) in accounts: print( Fore.RED + 'An account with this username already exists, try again with another username' + Fore.WHITE) continue print(Fore.BLUE + 'New password > 4 chars:' + Fore.WHITE, end=' ') password = input() if password == '': print( Fore.RED + 'Password can not be empty, try again with a different password.' + Fore.WHITE) continue print(Fore.BLUE + 'Password again:' + Fore.WHITE, end=' ') again_password = input() print() # Prints new line if password != again_password: print(Fore.RED + 'Passwords do not match!' + Fore.WHITE) continue elif password == again_password: loop_var = 1 print('Are you sure you want to create a new account with username ' + username + '? (yes/no):', end=' ') boolean = input() if boolean != 'yes': loop_var = 1 continue print() # Prints new line accounts[crypter.encode(username)] = crypter.encode(password) with open(program_accounts_dir, 'w') as f: json.dump(accounts, f, indent=4) print(Fore.GREEN + 'Successfully created account ' + username + '.' + Fore.WHITE) print('\n') # Prints 2 new lines