From 59485c3a7efd85629bb491cc7309dc413cd523ed Mon Sep 17 00:00:00 2001 From: Behnam <79264026+beh185@users.noreply.github.com> Date: Thu, 6 Jul 2023 13:36:15 +0000 Subject: [PATCH] Updated --- PasswordGenerator.py | 604 ++++++++++++++++++++++++------------------- README.md | 97 ++++--- 2 files changed, 388 insertions(+), 313 deletions(-) diff --git a/PasswordGenerator.py b/PasswordGenerator.py index e54b9bd..2ed503b 100644 --- a/PasswordGenerator.py +++ b/PasswordGenerator.py @@ -6,20 +6,27 @@ # GitHub: https://github.com/beh185 # Telegram: https://T.me/dr_xz -# e-mail: BehnamH.dev@gmail.com +# e-mail: Behii@tutanota.com # ____________________________________________ #import part -from os import name, system, path, getcwd -from colorama import Fore, init -from random import choice, randint -from pathlib import Path +from os import name, system, path +from random import choice from shutil import move from time import sleep -from datetime import date, datetime +from datetime import datetime from urllib.request import urlretrieve -import pyfiglet - +import json +try: + from colorama import Fore, init + import pyfiglet + +except ImportError: + print('Make sure that you are connected to internet!') + sleep(3) + system('pip install colorama') + system('pip install pyfiglet') + exit('> Run the program again!') print(Fore.CYAN + "Please wait ..." + Fore.RESET) init() @@ -69,32 +76,32 @@ def Ambiguous(): # making functions to if passwords.txt exist adding number at end of it - def rename_if_file_exists(file_name_number): - file_name_number = file_name_number - while path.exists('passwords{number}.txt'.format(number=str(file_name_number))): + while path.exists(f'passwords{str(file_name_number)}.txt'): file_name_number += 1 global file_name - file_name = 'passwords{number}.txt'.format( - number=str(file_name_number)) + file_name = f'passwords{str(file_name_number)}.txt' def exists_checker(the_path): if not path.exists(the_path): - raise FileExistsError( + exit( Fore.RED + f'"{the_path}" is not exists. Enter file name correctly !' + Fore.RESET) # check if user install pyfiglet ANSI Shadow font -pyfiglet_path = pyfiglet.__file__.replace('__init__.py', 'fonts/') +if name == 'nt': + pyfiglet_path = pyfiglet.__file__.replace('__init__.py', 'fonts\\') +else: + pyfiglet_path = pyfiglet.__file__.replace('__init__.py', 'fonts/') if not path.exists(pyfiglet_path + 'ANSI Shadow.flf'): - download_permistion = input( - Fore.RED + 'require font for this script is not installed. Do you want to download it ? [Y/n] ') - if download_permistion == 'y' or download_permistion == 'Y' or download_permistion == 'yes' or download_permistion == 'Yes' or download_permistion == 'YES' or download_permistion == 'yEs' or download_permistion == 'yeS' or download_permistion == 'yES' or download_permistion == '': + download_permission = input( + Fore.RED + '- Require font for this script is not installed. Do you want to download it ? [Y/n] ') + if download_permission.lower() == 'y' or download_permission.lower() == 'yes' or download_permission == '': print(Fore.GREEN + 'Downloading ... ' + Fore.RESET) urlretrieve( "https://github.com/xero/figlet-fonts/raw/master/ANSI%20Shadow.flf", 'ANSI Shadow.flf') - + move('ANSI Shadow.flf', pyfiglet_path+'ANSI Shadow.flf') else: exit('This font is require for run this script. please install it first.') @@ -103,224 +110,267 @@ def exists_checker(the_path): # first menu print(Fore.YELLOW + pyfiglet.figlet_format('Password tool', font='ANSI Shadow') + Fore.GREEN + '''[1] - Just one password -[2] - Generate multiple passwords -[3] - sort password list -[4] - delete duplicate password in password list -[5] - add password lists together\n''' + Fore.RESET) - -first_menu_choice = int( - input(Fore.MAGENTA + '⹃ Enter number of your choice -> ' + Fore.RESET)) +[2] - Generate password list +[3] - Sort password list +[4] - Delete duplicate password in password list +[5] - Merge password lists\n''' + Fore.RESET) +try: + first_menu_choice = int( + input(Fore.MAGENTA + '⹃ Enter number of your choice -> ' + Fore.RESET)) +except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) +except ValueError: + exit(Fore.RED + 'Error ! Pay attention that your answer must be a number between 1-5.' + Fore.RESET) + clear_screen() # one password if(first_menu_choice == 1): # second menu for "just one password" - print(Fore.YELLOW + pyfiglet.figlet_format('single password', font='ANSI Shadow') + Fore.GREEN + '''[1] - Include Symbols ( e.g. !@#$%^&* ) + print(Fore.YELLOW + pyfiglet.figlet_format('single password', font='ANSI Shadow') + + '[1] - Show previous passwords\n[2] - Generate password') + try: + second_menu_choice = int(input(Fore.GREEN + '\n⹃ Enter number of the part that you need -> ' + Fore.RESET)) + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except ValueError: + exit(Fore.RED + 'Error! Pay attention that your answer must be 1 or 2.') + except: + print(Fore.RED + 'Some things went wrong, Please try again !' + Fore.RED) + # Show previous passwords + if second_menu_choice == 1: + clear_screen() + print(Fore.YELLOW + pyfiglet.figlet_format('single password', font='ANSI Shadow')) + try: + password_key: str = input( + Fore.MAGENTA + ' ⹃ Enter key of password -> ' + Fore.RESET) + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except: + print(Fore.RED + 'Some things went wrong, Please try again !' + Fore.RED) + try: + with open(__file__.replace('PasswordGenerator.py', 'Just_one_password.json'),'r') as fn: + password_data = json.load(fn) + print(Fore.MAGENTA + f'''The password is = {Fore.GREEN + password_data[password_key]['password'] + Fore.MAGENTA} +The year it was saved = {Fore.GREEN + str(password_data[password_key]['Year']) + Fore.MAGENTA} +The month it was saved = {Fore.GREEN + str(password_data[password_key]['month']) + Fore.MAGENTA} +The day it was saved = {Fore.GREEN + str(password_data[password_key]['day']) + Fore.MAGENTA} +The time it was saved = {Fore.GREEN + str(password_data[password_key]['hour']) + ':' + str(password_data[password_key]['min']) + Fore.MAGENTA}''' + Fore.RESET) + except FileNotFoundError: + exit(Fore.RED + 'Error! Data base didn\'t found.\nFirst generate some passwords and then use this part' + Fore.RESET) + except KeyError: + exit(Fore.RED + "Error! The password's key wasn't correct. Try again. " + Fore.RESET) + # Generate password + elif second_menu_choice == 2: + clear_screen() + print(Fore.YELLOW + pyfiglet.figlet_format('single password', font='ANSI Shadow') + Fore.GREEN + '''[1] - Include Symbols ( e.g. !@#$%^&* ) [2] - Include Numbers ( e.g. 12345 ) [3] - Include Lowercase Characters ( e.g. abcdefgh ) [4] - Include Uppercase Characters ( e.g. ABCDEFGH ) [5] - Include Ambiguous Characters( e.g. { } [ ] ( ) / \ ' " ` ~ , ; : . < > ) -''' + Fore.RESET) - second_menu_choice = input( - Fore.MAGENTA + ' ⹃ Enter number of your choices. e.g : 1 2 5 -> ' + Fore.RESET) - # check if user Enter their choice correctly - second_menu_choice = list(second_menu_choice) - if '1' not in second_menu_choice and '2' not in second_menu_choice and '3' not in second_menu_choice and '4' not in second_menu_choice and '5' not in second_menu_choice: - exit(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - - if '1' in second_menu_choice: - if second_menu_choice.count('1') != 1: - exit(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - - if '2' in second_menu_choice: - if second_menu_choice.count('2') != 1: - exit(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - - if '3' in second_menu_choice: - if second_menu_choice.count('3') != 1: - exit(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - - if '4' in second_menu_choice: - if second_menu_choice.count('4') != 1: - exit(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - - if '5' in second_menu_choice: - if second_menu_choice.count('5') != 1: - exit(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - - list_for_check_superfluous = list( - '!@#$%^&*=67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{}[]()/\'"`~,;:.<>') - for i in list_for_check_superfluous: - if i in second_menu_choice: - exit(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - - # make passwords_list complete - if ('1' in second_menu_choice): - symbols() - if ('2' in second_menu_choice): - numbers() - if('3' in second_menu_choice): - lowercase() - if('4' in second_menu_choice): - uppercase() - if('5' in second_menu_choice): - Ambiguous() - - # changing to list to use choice meted - passwords_list = list(passwords_list) - - clear_screen() - #third menu - print(Fore.YELLOW + pyfiglet.figlet_format('passwords', - font='ANSI Shadow') + Fore.RESET) - password_length = int( - input(Fore.BLUE + '⹃ Enter password length -> ' + Fore.RESET)) - - # the password - generated_password = '' - - # Generating password - for _ in range(password_length): - letter = choice(passwords_list) - generated_password = generated_password + letter - print(Fore.BLUE + 'Your password is : ' + generated_password + Fore.RESET) - if not path.exists('.Just_one_password.txt'): - with open('.Just_one_password.txt','w') as fn: - date1 = date.today() - time = datetime.now().strftime("%H:%M:%S") - pwd = getcwd() - fn.write(f'modified in = [{date1, " - ",time}] The password: ' + generated_password+ '\n') - - fn.close() - else: - with open('.Just_one_password.txt', 'a') as fn: - date1 = date.today() - time = datetime.now().strftime("%H:%M:%S") - pwd = getcwd() - fn.write(f"\nmodified in = [{date1} {time}] The password = " + generated_password+'\n') + ''' + Fore.RESET) + try: + included_obj: str = input( + Fore.MAGENTA + ' ⹃ Enter number of your choices. e.g : 1 2 5 -> ' + Fore.RESET).split() + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except: + print(Fore.RED + 'Some things went wrong, Please try again !' + Fore.RED) + # check if user Enter their choice correctly + for items in included_obj: + try: + int(items) + except ValueError: + exit(Fore.RED + 'Error! Pay attention that your answer must be numbers between 1-5 and separated by spaces') + if len(items) != 1 or int(items) > 5: + exit(Fore.RED + 'Error! Pay attention that your answer must be numbers between 1-5 and separated by spaces') + # make passwords_list complete + if ('1' in included_obj): + symbols() + if ('2' in included_obj): + numbers() + if('3' in included_obj): + lowercase() + if('4' in included_obj): + uppercase() + if('5' in included_obj): + Ambiguous() + + # changing to list to use choice method + passwords_list = list(passwords_list) + + clear_screen() + #third menu + print(Fore.YELLOW + pyfiglet.figlet_format('passwords', + font='ANSI Shadow') + Fore.RESET) + try: + password_length = int( + input(Fore.BLUE + '⹃ Enter password length -> ' + Fore.RESET)) + except ValueError: + exit(Fore.RED + 'Error! Your answer must be numbers') + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + + + # the password + generated_password = '' + + # Generating password + try: + for _ in range(password_length): + letter = choice(passwords_list) + generated_password = generated_password + letter + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except: + print(Fore.RED + 'Some thing went wrong try again!'+ Fore.RESET) + print(Fore.BLUE + 'Your password is : ' + generated_password + Fore.RESET) + + if not path.exists(__file__.replace('PasswordGenerator.py', 'Just_one_password.json')): + with open(__file__.replace('PasswordGenerator.py', 'Just_one_password.json'),'w') as f: + password_data = { + 'password_1':{'password': generated_password, + 'Year': datetime.today().year, + 'month': datetime.now().strftime("%B"), + 'day':datetime.now().strftime("%d"), + 'hour':datetime.now().strftime("%H"), + 'min':datetime.now().strftime("%M") + } + } + password_data = json.dump(password_data,f ,indent=4) + print(Fore.LIGHTGREEN_EX + 'Your passwords by key of => ' + Fore.CYAN + 'password_1' + Fore.LIGHTGREEN_EX + + '\nUse this key to access the password on Just "one password/Show previous passwords" section' + Fore.RESET) + else: + with open(__file__.replace('PasswordGenerator.py', 'Just_one_password.json'),'r') as fn: + password_data = json.load(fn) + len_password_data = len(password_data) + with open(__file__.replace('PasswordGenerator.py', 'Just_one_password.json'),'w') as fn: + password_data[f'password_{len_password_data+1}'] = { + 'password': generated_password, + 'Year': datetime.today().year, + 'month': datetime.now().strftime("%B"), + 'day':datetime.now().strftime("%d"), + 'hour':datetime.now().strftime("%H"), + 'min':datetime.now().strftime("%M")} + password_data = json.dump(password_data,fn ,indent=4) - sleep(1) - show_previous_passwords = input( - Fore.CYAN + '\n\n- Do you want to show previous passwords that you generated? [Y/n] ' + Fore.RESET) - if show_previous_passwords == 'y' or show_previous_passwords == 'Y' or show_previous_passwords == 'yes' or show_previous_passwords == 'Yes' or show_previous_passwords == 'YES' or show_previous_passwords == 'yEs' or show_previous_passwords == 'yeS' or show_previous_passwords == 'yES' or show_previous_passwords== '': - with open('.Just_one_password.txt', 'r') as fn: - content = fn.read() - print(content) - print( - Fore.GREEN + '\n\nThe passwords save in ' + pwd + '/.Just_one_password.txt' + Fore.RESET) - -# multiple passwords + print(Fore.LIGHTGREEN_EX + 'Your passwords by key of => ' + Fore.CYAN + f'password_{len_password_data+1}' + Fore.LIGHTGREEN_EX + + '\nUse this key to access the password on "Just one password/Show previous passwords" section' + Fore.RESET) + else: + exit(Fore.RED + 'Error! Please enter the number of the part that you need correctly!'+ Fore.RESET) +# password list elif (first_menu_choice == 2): # second menu for "multiple passwords" - print(Fore.YELLOW + pyfiglet.figlet_format('multiple password', font='ANSI Shadow') + Fore.GREEN + '''[1] - Include Symbols ( e.g. !@#$%^&* ) + print(Fore.YELLOW + pyfiglet.figlet_format('Password list', font='ANSI Shadow') + Fore.GREEN + '''[1] - Include Symbols ( e.g. !@#$%^&* ) [2] - Include Numbers ( e.g. 12345 ) [3] - Include Lowercase Characters ( e.g. abcdefgh ) [4] - Include Uppercase Characters ( e.g. ABCDEFGH ) [5] - Include Ambiguous Characters( e.g. { } [ ] ( ) / \ ' " ` ~ , ; : . < > ) ''' + Fore.RESET) - second_menu_choice = input( - Fore.MAGENTA + ' ⹃ Enter number of your choice. e.g : 1 2 5 -> ' + Fore.RESET) - - # check if user Enter their choice correctly - second_menu_choice = list(second_menu_choice) - if '1' not in second_menu_choice and '2' not in second_menu_choice and '3' not in second_menu_choice and '4' not in second_menu_choice and '5' not in second_menu_choice: - exit(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - if '1' in second_menu_choice: - if second_menu_choice.count('1') != 1: - print(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - exit() - if '2' in second_menu_choice: - if second_menu_choice.count('2') != 1: - print(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - exit() - - if '3' in second_menu_choice: - if second_menu_choice.count('3') != 1: - print(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - exit() - - if '4' in second_menu_choice: - if second_menu_choice.count('4') != 1: - print(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - exit() - if '5' in second_menu_choice: - if second_menu_choice.count('5') != 1: - print(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - exit() - list_for_check_superfluous = list( - '!@#$%^&*=67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{}[]()/\'"`~,;:.<>') - - for i in list_for_check_superfluous: - if i in second_menu_choice: - print(Fore.RED + 'Please, Enter number from menu correctly and separate them with space (e.g : 1 2 5)' + Fore.RESET) - exit() - # make passwords_list complete - if ('1' in second_menu_choice): + try: + included_obj: str = input( + Fore.MAGENTA + ' ⹃ Enter number of your choices. e.g : 1 2 5 -> ' + Fore.RESET).split() + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except: + print(Fore.RED + 'Some things went wrong, Please try again !' + Fore.RED) + # check if user Enter their choice correctly + # check if user Enter their choice correctly + for items in included_obj: + try: + int(items) + except ValueError: + exit(Fore.RED + 'Error! Pay attention that your answer must be numbers between 1-5 and separated by spaces') + if len(items) != 1 or int(items) > 5: + exit(Fore.RED + 'Error! Pay attention that your answer must be numbers between 1-5 and separated by spaces') + # add obj that user want to password_list + if ('1' in included_obj): symbols() - if ('2' in second_menu_choice): + if ('2' in included_obj): numbers() - if('3' in second_menu_choice): + if('3' in included_obj): lowercase() - if('4' in second_menu_choice): + if('4' in included_obj): uppercase() - if('5' in second_menu_choice): + if('5' in included_obj): Ambiguous() - # changing to list to use choice meted + # changing to list to use choice method passwords_list = list(passwords_list) clear_screen() #third menu print(Fore.YELLOW + pyfiglet.figlet_format('password', font='ANSI Shadow') + Fore.RESET) - password_number = int( - input(Fore.BLUE + 'Enter how many passwords do you want to generate -> '+ Fore.RESET)) - password_length = int( - input(Fore.BLUE + '⹃ Enter password length -> ' + Fore.RESET)) + try: + password_number = int( + input(Fore.BLUE + 'Enter how many passwords do you want to generate -> '+ Fore.RESET)) + password_length = int( + input(Fore.BLUE + '⹃ Enter passwords length -> ' + Fore.RESET)) + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except ValueError: + exit(Fore.RED + '\nError! Only numbers are acceptable.' + Fore.RESET) + if (password_number > 500_000 or password_length > 100): + print(Fore.RED + 'Warning! You are going to produce huge amount of passwords this may take a long time and takes memory' + Fore.RESET) + sleep(3) print(Fore.BLUE + 'On it ... ' + Fore.RESET) - # the password - generated_passwords = [] - temp_generated_password = '' - # first 'for' is for number of password that must generate - for _ in range(password_number): - # second 'for' is for length of password that must generate - for _1 in range(password_length): - temp_generated_password += choice(passwords_list) - generated_passwords.append(temp_generated_password) - temp_generated_password = '' - # this variable is related to rename_if_file_exists functions and the value of this variable is name of the file - file_name = 'passwords.txt' - if path.exists('passwords.txt'): - rename_if_file_exists(1) - - # add generated passwords to file - with open(file_name, 'w') as fn: - the_passwords = '\n'.join(generated_passwords) - fn.write(the_passwords) - fn.close() - print(Fore.YELLOW + '\nYour file save as : ' + file_name + Fore.RESET) - print(Fore.GREEN + 'Done !' + Fore.RESET) + try: + # the password + generated_passwords = set() + temp_generated_password = str() + # first 'for' is for number of password that must generate + for _ in range(password_number): + # second 'for' is for length of password that must generate + for _1 in range(password_length): + temp_generated_password += choice(passwords_list) + generated_passwords.add(temp_generated_password) + temp_generated_password = str() + # this variable is related to rename_if_file_exists functions and the value of this variable is name of the file + file_name = 'passwords.txt' + if path.exists('passwords.txt'): + rename_if_file_exists(1) + + # add generated passwords to file + with open(__file__.replace('PasswordGenerator.py', file_name), 'w') as f: + the_passwords = '\n'.join(generated_passwords) + f.write(the_passwords) + f.close() + print(Fore.GREEN + '\nDone !' + Fore.RESET) + sleep(0.5) + print(Fore.BLUE + '\nDeleting duplicate passwords ...' + Fore.RESET) + sleep(1.5) + print(Fore.GREEN + '\nThe operation was successful!' + Fore.RESET) + print(Fore.YELLOW + '\nPassword list save as : ' + __file__.replace('PasswordGenerator.py', file_name) + Fore.RESET) + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except MemoryError: + exit(Fore.RED + 'There is no available ram left. Try make password list with less passwords' + Fore.RED) # sort password list elif first_menu_choice == 3: print(Fore.YELLOW + pyfiglet.figlet_format('sort password', font='ANSI Shadow') + Fore.RESET) - file_name = input( - Fore.MAGENTA + '⹃ Enter name of your password list [It\'s better to enter complete path of it] -> ' + Fore.RESET) + try: + file_name = input( + Fore.MAGENTA + '⹃ Enter your password list file path -> ' + Fore.RESET) + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except: + print(Fore.RED + 'Some things went wrong, Please try again !' + Fore.RED) + exists_checker(file_name) print(Fore.YELLOW + '\nOn it ...' + Fore.RESET) - fn = open(file_name, 'r') - sorted_fn = fn.readlines() - - for item in sorted_fn: - if '\n' not in item and item != '': - sorted_fn.remove(item) - sorted_fn.append(item+'\n') - # sort list - sorted_fn.sort() - - # make list to string + with open(file_name, 'r') as f: + sorted_fn : list = f.readlines() + #The last line doesn't have \n so when it sorted it will connect to another item + sorted_fn[-1] = sorted_fn[-1] +'\n' + # sort list + sorted_fn.sort() + f.close() + + # make list to string so can write it in file sorted_fn = ''.join(sorted_fn) # add it to file fn = open(file_name, 'w') @@ -331,29 +381,38 @@ def exists_checker(the_path): # delete duplicate elif first_menu_choice == 4: - # make menu + # menu print(Fore.YELLOW + pyfiglet.figlet_format('duplicate remover', font='ANSI Shadow') + Fore.RESET) - which_meted = int(input( - Fore.GREEN + '[1] - stable meted [slow]\n[2] - unstable meted [fast]\n\n- Please, enter number of your choice -> ' + Fore.RESET)) - file_name = input( - Fore.MAGENTA + '\n⹃ Enter name of your password list [It\'s better to enter complete path of it] -> ' + Fore.RESET) + try: + try: + which_method = int(input( + Fore.GREEN + '[1] - Slow method [won\'t change the order]\n[2] - Fast method [change the order]\n\n- Please, enter number of your choice -> ' + Fore.RESET)) + except ValueError: + exit(Fore.RED + '\nError! Only numbers are acceptable.' + Fore.RESET) + file_name = input( + Fore.MAGENTA + '\n⹃ Enter path of your password list -> ' + Fore.RESET) + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except: + print(Fore.RED + 'Some things went wrong, Please try again !' + Fore.RED) + # check if the file exists | this functions defined in line 68 exists_checker(file_name) - if which_meted == 1: + print(Fore.YELLOW + 'Starting the operation' + Fore.RESET) + if which_method == 1: fn = open(file_name, 'r') the_file_content = fn.readlines() - # adding '\n' to last item till all of item have '\n' - last_fn_item = the_file_content.pop() - last_fn_item = str(last_fn_item) + '\n' - the_file_content.append(last_fn_item) + #The last line doesn't have \n so when it sorted it will connect to another item + the_file_content[-1] = the_file_content[-1] +'\n' # notice user if their system can handle the file - if len(the_file_content) > 1500000: - print( - Fore.RED + '\nThe file is large ! It\'s may take long time. It\'s better to use strong system.') - system_permistion = input( + if len(the_file_content) > 1_000_000: + print(Fore.RED + + 'Warning! You are going to produce huge amount of passwords this may take a long time and takes memory' + Fore.RESET) + + system_permission = input( Fore.GREEN + 'Do you want to continue ? [y/N] ' + Fore.RESET) - if system_permistion == 'y' or system_permistion == 'Y' or system_permistion == 'yes' or system_permistion == 'Yes' or system_permistion == 'YES' or system_permistion == 'yEs' or system_permistion == 'yeS' or system_permistion == 'yES': + if system_permission.lower() == 'y' or system_permission.lower() == 'yes': print(Fore.YELLOW + '\nOn it ...' + Fore.RESET) # removing duplicate in list @@ -362,93 +421,94 @@ def exists_checker(the_path): if the_file_content.count(i) != 1: for k in range(count_i-1): the_file_content.remove(i) + print(Fore.GREEN + "The duplicate passwords are now deleted" + Fore.RESET) + else: - exit(Fore.LIGHTRED_EX + '\nExiting ... ' + Fore.RESET) + exit(Fore.RED + '\nPermission denied!' + Fore.RESET) + else: + # removing duplicate in list + for i in the_file_content: + count_i = the_file_content.count(i) + if the_file_content.count(i) != 1: + for k in range(count_i-1): + the_file_content.remove(i) + print(Fore.GREEN + "The duplicate passwords are now deleted" + Fore.RESET) + - elif which_meted == 2: + elif which_method == 2: print(Fore.YELLOW + '\nOn it ...' + Fore.RESET) fn = open(file_name, "r") - the_file_content = fn.readlines() # make it set because set don't keep 2 same thing on itself - the_file_content = set(the_file_content) - the_file_content = list(the_file_content) - the_file_content = "".join(the_file_content) - fn = open(file_name, "w") - fn.write(the_file_content) - fn.close() - print("The duplicate passwords are now deleted") + the_file_content = set(fn.readlines()) + print(Fore.GREEN + "The duplicate passwords are now deleted" + Fore.RESET) else: - exit(Fore.RED + "Please enter name of the file correctly" + Fore.RESET) + exit(Fore.RED + "Please enter the number of the part that you need correctly!" + Fore.RESET) # make the list string and put it into file - fn_str = ''.join(the_file_content) + the_file_content = "".join(the_file_content) fn_w = open(file_name, 'w') - fn_w.write(fn_str) + fn_w.write(the_file_content) fn_w.close() print(Fore.YELLOW + '\nYour file save as : ' + file_name + Fore.RESET) print(Fore.GREEN + 'Done !' + Fore.RESET) # adding password list together elif first_menu_choice == 5: - print(Fore.YELLOW + '''███████╗██╗ ██╗████████╗███████╗███╗ ██╗██████╗ -██╔════╝╚██╗██╔╝╚══██╔══╝██╔════╝████╗ ██║██╔══██╗ -█████╗ ╚███╔╝ ██║ █████╗ ██╔██╗ ██║██║ ██║ -██╔══╝ ██╔██╗ ██║ ██╔══╝ ██║╚██╗██║██║ ██║ -███████╗██╔╝ ██╗ ██║ ███████╗██║ ╚████║██████╔╝ -╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚═════╝ - -██████╗ █████╗ ███████╗███████╗██╗ ██╗ ██████╗ ██████╗ ██████╗ -██╔══██╗██╔══██╗██╔════╝██╔════╝██║ ██║██╔═══██╗██╔══██╗██╔══██╗ -██████╔╝███████║███████╗███████╗██║ █╗ ██║██║ ██║██████╔╝██║ ██║ -██╔═══╝ ██╔══██║╚════██║╚════██║██║███╗██║██║ ██║██╔══██╗██║ ██║ -██║ ██║ ██║███████║███████║╚███╔███╔╝╚██████╔╝██║ ██║██████╔╝ -╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ 𝒍𝒊𝒔𝒕 '''+ Fore.RESET) - + print(Fore.YELLOW + pyfiglet.figlet_format('Pass list merger', + font='ANSI Shadow') + Fore.RESET) # getting all file name from user - all_password_list_name = [] - all_password_list_content = [] - file_name = input( - Fore.MAGENTA + '\n1 - Enter your file name -> ' + Fore.RESET) - all_password_list_name.append(file_name) + all_password_list_content: list = list() + try: + file_name = input( + Fore.MAGENTA + '\n1 - Enter your file path -> ' + Fore.RESET) + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except: + print(Fore.RED + 'Some things went wrong, Please try again !' + Fore.RED) + exists_checker(file_name) + file_name = open(file_name, 'r').readlines() + + #The last line doesn't have \n so when it sorted it will connect to another item + file_name[-1] = file_name[-1] +'\n' + all_password_list_content.extend(file_name) # getting name of the file from user - status = True input_number = 2 - while status == True: - file_name = input( - Fore.MAGENTA + f'{input_number} - Enter your file name -> ' + Fore.RESET) - all_password_list_name.append(file_name) + while True: + try: + file_name = input( + Fore.MAGENTA + f'{input_number} - Enter your file path -> ' + Fore.RESET) + except KeyboardInterrupt: + exit(Fore.RED + '\nThe operation canceled by user' + Fore.RESET) + except: + print(Fore.RED + 'Some things went wrong, Please try again !' + Fore.RED) + + exists_checker(file_name) + file_name = open(file_name, 'r').readlines() + + #The last line doesn't have \n so when it sorted it will connect to another item + file_name[-1] = file_name[-1] +'\n' + + all_password_list_content.extend(file_name) user_request = input( - Fore.YELLOW + '\nDo you have anymore password list ? [Y/n] ' + Fore.RESET) - if user_request == 'y' or user_request == 'Y' or user_request == 'yes' or user_request == 'Yes' or user_request == 'YES' or user_request == 'yEs' or user_request == 'yeS' or user_request == 'yES' or user_request == '': + Fore.YELLOW + '\nWant to add more password list ? [Y/n] ' + Fore.RESET) + if user_request == 'y' or user_request == 'yes' or user_request == '': clear_screen() - print(Fore.YELLOW + pyfiglet.figlet_format('extend password', - font='ANSI Shadow') + "𝒍𝒊𝒔𝒕" + Fore.RESET) + print(Fore.YELLOW + pyfiglet.figlet_format('Pass list merger', + font='ANSI Shadow') + Fore.RESET) input_number += 1 else: - status == False break + print(Fore.BLUE + 'On it ... ' + Fore.RESET) - # check if all of the name are exists - for i in all_password_list_name: - exists_checker(i) - # open all file and adding them to one list. - for file_name in all_password_list_name: - password_list = open(file_name, 'r') - password_list = password_list.readlines() - all_password_list_content.extend(password_list) - # adding '\n' to all of the item because some of them have and some of them not and in removing duplicate we go to problem - for item in all_password_list_content: - if '\n' not in item and item != '': - all_password_list_content.remove(item) - all_password_list_content.append(item+'\n') + # set file name file_name = 'passwords.txt' if path.exists('passwords.txt'): rename_if_file_exists(1) password_list = open(file_name, 'w') - all_password_list_content = ''.join(all_password_list_content) - password_list.write(all_password_list_content) + all_password_list_content_str: str = "".join(all_password_list_content) + password_list.write(all_password_list_content_str) print(Fore.YELLOW + 'Your file save as : ' + file_name + Fore.RESET) print(Fore.GREEN + 'Done !' + Fore.RESET) else: - print(Fore.RED + 'Please, Enter number correctly !' + Fore.RESET) + exit(Fore.RED + 'Error ! Pay attention that your answer must be a number between 1-5.' + Fore.RESET) \ No newline at end of file diff --git a/README.md b/README.md index a736ce8..a694671 100644 --- a/README.md +++ b/README.md @@ -3,48 +3,52 @@ With this script you can : - [Generate one password](#generate-one-password) -- [Generate multiple password](#generate-multiple-password) -- [sort password list](#sort-password-list) -- [delete duplicate passwords in password list](#delete-duplicate-passwords-in-password-list) -- [add password lists together](#add-password-lists-together) +- [Generate password list](#generate-password-list) +- [Sort password list](#sort-password-list) +- [Delete duplicate passwords in password list](#delete-duplicate-passwords-in-password-list) +- [Merge password lists](#merge-password-lists) --- # Dependencies -This script use [**pyfiglet**](https://pypi.org/project/pyfiglet/) and [**colorama**](https://pypi.org/project/colorama/) so you need to install them with these commands :\ -for install colorama : `pip install colorama`\ -for install pyfiglet : `pip install pyfiglet` +This program use [**pyfiglet**](https://pypi.org/project/pyfiglet/) and [**colorama**](https://pypi.org/project/colorama/) as external library.\ +By running the program this libraries will be downloaded, but if there were any problem you can install them manually by following command :\ +> for install colorama : `pip install colorama`\ +> for install pyfiglet : `pip install pyfiglet` -![](https://user-images.githubusercontent.com/79264026/178007880-62568118-e073-4c17-8946-8c19808293fd.png)\ -Also pyfiglet need [ANSI Shadow](https://github.com/xero/figlet-fonts/blob/master/ANSI%20Shadow.flf) font that will install automatically after running script. +![](https://user-images.githubusercontent.com/79264026/178007880-62568118-e073-4c17-8946-8c19808293fd.png) +Also program need [ANSI Shadow](https://github.com/xero/figlet-fonts/blob/master/ANSI%20Shadow.flf) that will be downloaded after running program --- -# Generate one password +# YouTube Tutorial +![](https://youtu.be/hlkBS0gWI7g) +--- +# Generate One Password In this part you can generate one password quickly. -It's good for sign up in site or app that you want use strong password and then save password somewhere . - -![generate-one-password1](https://user-images.githubusercontent.com/79264026/178008051-5cac436d-4b55-4050-b1a9-1a0185f0c2be.png) +It's really good for signing up in sites or apps when you want use strong password.\ +![]() +Also after generating the password it will be save in a **json** file, so you can access it later by: -> running program -> Just one password -> Show previous passwords +![](screenshot) -In this menu you can choose which characters be on you password. Enter number of your choice like this -> `1 2 5` \ -if you want to separate the number use space. if you use anything else you will get error. +In this menu you can choose what characters you want in the password.\ +When you want to enter number of your choices, pay attention that numbers must be between **1-5** -> `1 2 5` \ +And use **spaces** when you want to separate -![generate-one-password2](https://user-images.githubusercontent.com/79264026/178008554-51322498-7582-465a-8806-58037441f4a5.png) +![](screenshot) In this menu you choose length of password. For example if you enter **8** the script will return a password with 8 characters. like -> `12345678` -![generate-one-password3](https://user-images.githubusercontent.com/79264026/178008765-d489eeec-453d-45d3-9c76-1741e3d25a47.png) - -Also we save the password that you generate in hidden file name `.Just_one_password.txt`. you can access to your previous password in the end of **generate one password** part +![](screenshot) +We save the passwords that you generate in **Just_one_password.json** file. --- -# Generate multiple password | password list -In this part you can generate passwords and export it as txt file. Actually you are creating password list. - -![multiple1](https://user-images.githubusercontent.com/79264026/178008895-0d931dd5-da7b-4c75-88d0-8bdedacbfe47.png) - -This part is like [Generate one password](#generate-one-password). In this menu you can choose which characters be on you passwords. Enter number of your choice like this -> `1 2 5` \ -if you want to separate the number use space. if you use anything else you will get error. +# Generate password list +In this part you can generate passwords and export it as txt file. -![Generate multiple password2](https://user-images.githubusercontent.com/79264026/178008959-2b8b314b-7628-4131-8e5a-94357f7864df.png) +![](screenshot) +In this menu you can choose what characters you want in the password.\ +When you want to enter number of your choices, pay attention that numbers must be between **1-5** -> `1 2 5` \ +And use **spaces** when you want to separate +![](screenshot) In this menu you choose **number** of password that script will generate. In second question you choose length of password. For example if you enter **8** the script will return a password with 8 characters. like -> `12345678` @@ -52,30 +56,41 @@ In this menu you choose **number** of password that script will generate. In sec # sort password list On this part you can sort your password list. For example if your password is like this `125, 142, 111` it will change to -> `111, 125, 142` . -![sort-password-list](https://user-images.githubusercontent.com/79264026/178009195-374d9c3f-cf80-4501-8907-12319a889416.png) - +![](screenshot) Only thing that you must do is enter name of your file :)\ -Remember that if your file is not in same directory of terminal enter complete path of your password list.\ -For example : I'm running terminal in `/home/user/` directory but the password list is in `/home/user/Desktop/` so in script i must enter `/home/user/Desktop/Your_file_name`.\ -but if I'm running terminal in `/home/user/` and my password list is in there too, I just need to enter name of the password list +**If you get "file is not exists. Enter file name correctly !" error but you are sure that file exist try to enter complete path of file** +## finding complete path +In windows: +> Right click the file then choose copy as a path option\ + +![]() + +In linux: +> use "pwd" command and add file name at the end of it --- # delete duplicate passwords in password list -If one password is repeated in password list this part of script will delete it and keep just one of them. +If one password is repeated in password list this part of program will delete it and keep just one of them. -![delete duplicate](https://user-images.githubusercontent.com/79264026/178009351-5c51e989-7369-4d75-8994-aea104dc2ffa.png) +![](screenshot) +On this menu we have two method **slow method** and **fast method**. +**Slow method** use more memory and it's take long time to delete duplicates, but it doesn't disrupts the order of password list . -On this menu we have to meted **slow** and **fast**. +**Fast method** It's much faster than slow mood but only problem is that it disrupts the order of your password list. +if you don't care about the order of your file use this method and then sort it with [sort password list](#sort-password-list) part. -**Slow mood** use more memory and it's take long time to delete duplicates. but it's stable and it doesn't disrupts the order of password list . +**If you get "file is not exists. Enter file name correctly !" error but you are sure that file exist try to enter complete path of file** -**Fast mood** It's much faster than slow mood but only problem is it's disrupts the order of your password list. -if you don't care about the order of your file use this meted and then sort it with [sort password list](#sort-password-list) part. +[**Explanation for finding complete path**](#finding-complete-path) --- -# add password lists together -In this part of script you can add your password lists together and make your password lists into single file. +# Merge password lists +In this part of program you can merge your password lists and make your password lists into single file. +![](screenshot) + +**If you get "file is not exists. Enter file name correctly !" error but you are sure that file exist try to enter complete path of file** - ![add-password-list-together](https://user-images.githubusercontent.com/79264026/178009399-e1947fcb-5453-4eb2-a5a7-3a2677ef42ee.png) +[**Explanation for finding complete path**](#finding-complete-path) + \ No newline at end of file