From d44802aa639b44dbdf98c6e6799b4ef7cabaa4ff Mon Sep 17 00:00:00 2001 From: PieBerlin Date: Tue, 23 Dec 2025 21:09:31 +0300 Subject: [PATCH 1/2] dynamic-password-generator --- Password-Generator/dynamic_password.py | 73 ++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Password-Generator/dynamic_password.py diff --git a/Password-Generator/dynamic_password.py b/Password-Generator/dynamic_password.py new file mode 100644 index 0000000..7321659 --- /dev/null +++ b/Password-Generator/dynamic_password.py @@ -0,0 +1,73 @@ +"""_summary_ + implementing password generation program that allows symbols and capital letters if the user wants to include them + + Returns: + password +""" + + + +import random + + +#constants +SMALL_LETTERS="abcdefghijklmnopqrstuvwxyz" +CAPITAL_LETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZ" +SYMBOLS="~!@#$%^&*()_-+={[}]|:;<>?" +MIN_LENGTH=12 +MAX_LENGTH=24 + + +#function to generate the password +def dynamic_password(passlength,capitals=False,symbols=False): + characters=SMALL_LETTERS + if capitals: + characters+=CAPITAL_LETTERS + if symbols: + characters+=SYMBOLS + password="" + for i in range(0,passlength): + randomletter=random.choice(characters) + password+=(randomletter) + + return password + +#Function to take user inputs and validate them +def inputs_validation(): + while True: + + pass_length=input(f"Enter password length ({MIN_LENGTH}-{MAX_LENGTH}): ") + input_capitals=input("Do we include capitals (y/n): ").strip().lower() + input_symbols=input("Do we include symbols (y/n): ").strip().lower() + + # 1. Validate both inputs at once + if input_capitals not in ['y', 'n'] or input_symbols not in ['y', 'n']: + print("Please type 'y' or 'n' for the options.") + continue # Restarts the loop to ask again + + #2. convert to booleans + capitals=(input_capitals=='y') + symbols=(input_symbols=='y') + + if pass_length.isdigit(): + #validate password length + length=int(pass_length) + if 12<=length<=24: + return length,capitals,symbols + else: + print("Please enter password length within the range!!") + continue + print("Password length should be a Number") + + + + + +def main(): + length,capitals,symbols=inputs_validation() + password=dynamic_password(length,capitals,symbols) + print(f"Your Generated Password is : {password}") + + +if __name__ == "__main__": + main() \ No newline at end of file From 31acebaef63a9efe8255b13fe33eeaf307aba66a Mon Sep 17 00:00:00 2001 From: PieBerlin Date: Sun, 28 Dec 2025 10:40:17 +0300 Subject: [PATCH 2/2] formatted-code --- Password-Generator/dynamic_password.py | 123 +++++++++++++++---------- 1 file changed, 75 insertions(+), 48 deletions(-) diff --git a/Password-Generator/dynamic_password.py b/Password-Generator/dynamic_password.py index 7321659..8cb26f1 100644 --- a/Password-Generator/dynamic_password.py +++ b/Password-Generator/dynamic_password.py @@ -1,72 +1,99 @@ -"""_summary_ - implementing password generation program that allows symbols and capital letters if the user wants to include them - - Returns: - password """ +Password generation program that allows symbols and capital letters +based on user preferences. - +Returns: + str: Generated password +""" import random - -#constants -SMALL_LETTERS="abcdefghijklmnopqrstuvwxyz" -CAPITAL_LETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZ" -SYMBOLS="~!@#$%^&*()_-+={[}]|:;<>?" -MIN_LENGTH=12 -MAX_LENGTH=24 - - -#function to generate the password -def dynamic_password(passlength,capitals=False,symbols=False): - characters=SMALL_LETTERS +# Constants +SMALL_LETTERS = "abcdefghijklmnopqrstuvwxyz" +CAPITAL_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +SYMBOLS = "~!@#$%^&*()_-+={[}]|:;<>?" +MIN_LENGTH = 12 +MAX_LENGTH = 24 + + +def dynamic_password(passlength, capitals=False, symbols=False): + """ + Generate a random password based on specified criteria. + + Args: + passlength (int): Length of the password + capitals (bool): Whether to include capital letters + symbols (bool): Whether to include symbols + + Returns: + str: Generated password + """ + # Start with small letters as the base character set + characters = SMALL_LETTERS + + # Add capital letters if requested if capitals: - characters+=CAPITAL_LETTERS + characters += CAPITAL_LETTERS + + # Add symbols if requested if symbols: - characters+=SYMBOLS - password="" - for i in range(0,passlength): - randomletter=random.choice(characters) - password+=(randomletter) + characters += SYMBOLS + + # Generate password by randomly selecting characters + password = "" + for i in range(0, passlength): + random_letter = random.choice(characters) + password += random_letter return password -#Function to take user inputs and validate them -def inputs_validation(): - while True: - - pass_length=input(f"Enter password length ({MIN_LENGTH}-{MAX_LENGTH}): ") - input_capitals=input("Do we include capitals (y/n): ").strip().lower() - input_symbols=input("Do we include symbols (y/n): ").strip().lower() - # 1. Validate both inputs at once +def inputs_validation(): + """ + Get and validate user inputs for password generation. + + Returns: + tuple: (length, capitals, symbols) - validated user preferences + """ + while True: + # Get user inputs + pass_length = input(f"Enter password length ({MIN_LENGTH}-{MAX_LENGTH}): ") + input_capitals = input("Do we include capitals (y/n): ").strip().lower() + input_symbols = input("Do we include symbols (y/n): ").strip().lower() + + # 1. Validate both yes/no inputs at once if input_capitals not in ['y', 'n'] or input_symbols not in ['y', 'n']: print("Please type 'y' or 'n' for the options.") - continue # Restarts the loop to ask again - - #2. convert to booleans - capitals=(input_capitals=='y') - symbols=(input_symbols=='y') + continue # Restart the loop to ask again + + # 2. Convert inputs to booleans + capitals = (input_capitals == 'y') + symbols = (input_symbols == 'y') + # 3. Validate password length if pass_length.isdigit(): - #validate password length - length=int(pass_length) - if 12<=length<=24: - return length,capitals,symbols + length = int(pass_length) + + # Check if length is within valid range + if MIN_LENGTH <= length <= MAX_LENGTH: + return length, capitals, symbols else: print("Please enter password length within the range!!") continue - print("Password length should be a Number") - - - + + print("Password length should be a number") def main(): - length,capitals,symbols=inputs_validation() - password=dynamic_password(length,capitals,symbols) - print(f"Your Generated Password is : {password}") + """Main function to orchestrate the password generation process.""" + # Get validated user inputs + length, capitals, symbols = inputs_validation() + + # Generate password + password = dynamic_password(length, capitals, symbols) + + # Display the generated password + print(f"Your Generated Password is: {password}") if __name__ == "__main__":