Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: random_password_generator.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script generates random passwords by combining words, numbers, and special characters.
- It prompts the user to input a list of easily remembered words, which are then used to create a base password.
- The script randomly selects characters from the words, converts some to uppercase, and inserts random numbers
- and special characters at random positions to enhance password complexity.
- Functions:
- - generate_random_strings(word_list):
- Generate two random strings from the provided list.
- - generate_random_numbers():
- Generate two random numbers between 0 and 9.
- - generate_random_special_chars():
- Generate two random special characters from a predefined list.
- - generate_random_index(indices_list):
- Generate a random index from the provided list of indices.
- - main():
- Main function to execute the password generation process.
- Requirements:
- - Python 3.x
- Usage:
- 1. Run the script: python random_password_generator.py
- 2. Enter a list of easily remembered words separated by spaces when prompted.
- 3. The script will generate and display a random password combining words, numbers, and special characters.
- Example Output:
- Input a list of words separated by spaces: Randomly Generated Password Example
- Generated password: E#xaMpleR:and7o3mlY
- Additional Notes:
- - The script combines user-provided words to create a base password, ensuring it is memorable yet secure.
- - Random characters are selected from the words, and some are converted to uppercase for added complexity.
- - Random numbers and special characters are inserted at random positions to enhance password strength.
- """
- # Importing the random module
- import random
- def generate_random_strings(word_list):
- """
- Generate two random strings from the provided list.
- Parameters:
- word_list (list): List of strings to choose from.
- Returns:
- tuple: Two randomly chosen strings.
- """
- string1 = random.choice(word_list) # First random string
- word_list.remove(string1) # Remove to avoid repetition
- string2 = random.choice(word_list) # Second random string
- return string1, string2
- def generate_random_numbers():
- """
- Generate two random numbers between 0 and 9.
- Returns:
- tuple: Two randomly chosen numbers.
- """
- numbers = list(range(10))
- number1 = random.choice(numbers) # First random number
- numbers.remove(number1) # Remove to avoid repetition
- number2 = random.choice(numbers) # Second random number
- return number1, number2
- def generate_random_special_chars():
- """
- Generate two random special characters from a predefined list.
- Returns:
- tuple: Two randomly chosen special characters.
- """
- special_chars = ['~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '?', '+', '-', '_', ';', ':', '>', '<']
- char1 = random.choice(special_chars) # First random character
- special_chars.remove(char1) # Remove to avoid repetition
- char2 = random.choice(special_chars) # Second random character
- return char1, char2
- def generate_random_index(indices_list):
- """
- Generate a random index from the provided list of indices.
- Parameters:
- indices_list (list): List of indices to choose from.
- Returns:
- int: A randomly chosen index.
- """
- index = random.choice(indices_list)
- indices_list.remove(index)
- return index
- def main():
- # Take input from the user
- words = input('Input a list of words separated by spaces: ').split()
- # Create password using two random strings
- string1, string2 = generate_random_strings(words)
- password = string1 + string2
- # Uppercasing random characters in the password
- index_list = list(range(len(password)))
- for _ in range(2): # Perform twice
- index = generate_random_index(index_list)
- password = password[:index] + password[index].upper() + password[index+1:]
- # Adding random numbers to the password
- number1, number2 = generate_random_numbers()
- for number in (number1, number2):
- index = generate_random_index(index_list)
- password = password[:index] + str(number) + password[index:]
- # Adding random special characters to the password
- char1, char2 = generate_random_special_chars()
- for char in (char1, char2):
- index = generate_random_index(index_list)
- password = password[:index] + char + password[index:]
- # Printing the generated password
- print('\nGenerated password:', password)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement