Python3

Python script: Password Generator (with customizable options)


import random
import string

def generate_password(length=8, use_letters=True, use_digits=True, use_special_chars=False):
characters = ''
if use_letters:
characters += string.ascii_letters
if use_digits:
characters += string.digits
if use_special_chars:
characters += string.punctuation

if not any([use_letters, use_digits, use_special_chars]):
return 'Error: Please select at least one type of characters to generate a password.'

password = ''.join(random.choice(characters) for i in range(length))
return password

# Customize options to generate password
password_length = 12
include_letters = True
include_digits = True
include_special_chars = True

# Generate and print password
password = generate_password(password_length, include_letters, include_digits, include_special_chars)
print(password)

The above Python script defines a function `generate_password` that generates a password based on customizable options such as length, inclusion of letters, digits, and special characters. The function uses the `random` and `string` modules to generate random passwords.

The `generate_password` function takes the following parameters:
– `length`: The length of the password (default is 8)
– `use_letters`: Boolean flag to include letters in the password (default is True)
– `use_digits`: Boolean flag to include digits in the password (default is True)
– `use_special_chars`: Boolean flag to include special characters in the password (default is False)

Inside the function, it checks the options selected by the user and constructs the `characters` string accordingly. It then generates a password by randomly selecting characters from the `characters` string and returns the generated password.

In the script, customizable options are set for the password generation:
– `password_length`: Length of the password (12 characters)
– `include_letters`: Include letters in the password
– `include_digits`: Include digits in the password
– `include_special_chars`: Include special characters in the password

It then calls the `generate_password` function with the specified options and prints the generated password.

This script provides a flexible way to generate passwords with varying characteristics based on user preferences.