From e8b011d75451f9d0173e5c68c6bb9e33801ec52c Mon Sep 17 00:00:00 2001 From: Gauri Shirke Date: Thu, 2 Oct 2025 17:39:49 +0530 Subject: [PATCH] added PasswordGenerator.py file --- PasswordGenerator/PasswordGenerator.py | 38 ++++++++++++++++++++++++++ PasswordGenerator/README.md | 16 +++++++++++ 2 files changed, 54 insertions(+) create mode 100644 PasswordGenerator/PasswordGenerator.py create mode 100644 PasswordGenerator/README.md diff --git a/PasswordGenerator/PasswordGenerator.py b/PasswordGenerator/PasswordGenerator.py new file mode 100644 index 0000000..28f651c --- /dev/null +++ b/PasswordGenerator/PasswordGenerator.py @@ -0,0 +1,38 @@ +import random +import string + +def generate_password(length=12): + """ + Generate a random secure password. + + Parameters: + length (int): The length of the password (default is 12) + + Returns: + str: Generated password or None if length < 6 + """ + # Check if the requested password length is too short + if length < 6: + print("Password length should be at least 6 characters.") + return None + + # Combine all possible characters: letters (uppercase + lowercase), digits, and punctuation + characters = string.ascii_letters + string.digits + string.punctuation + + # Randomly select 'length' number of characters from the combined list + password = ''.join(random.choice(characters) for _ in range(length)) + + # Return the generated password + return password + +# This part runs when the script is executed directly +if __name__ == "__main__": + # Ask the user to input the desired password length + length = int(input("Enter password length: ")) + + # Generate the password using the function + password = generate_password(length) + + # If a password was successfully generated, print it + if password: + print("Generated password:", password) diff --git a/PasswordGenerator/README.md b/PasswordGenerator/README.md new file mode 100644 index 0000000..d97c20d --- /dev/null +++ b/PasswordGenerator/README.md @@ -0,0 +1,16 @@ +# PasswordGenerator + +## Description +This Python script generates a random, secure password. +It uses letters (uppercase & lowercase), numbers, and special characters to create strong passwords. + +## How to Use +1. Run the script: + +2. Enter the desired password length (minimum 6 characters). +3. The generated password will appear on the screen. + +## Use Cases +- Quickly generate strong passwords for online accounts +- Create passwords for apps or software projects +- Improve personal cybersecurity by avoiding weak passwords