Ad

Challenge: Write a program that generates a strong password from a phrase entered by the user.

Rules:

The program should prompt the user to enter a phrase to use as the basis for the password.
The program should validate the input to ensure that it contains at least 12 characters and at least one of each of the following types: uppercase letters, lowercase letters, digits, and symbols (punctuation marks and special characters).
If the input is valid, the program should generate a strong password using the following steps:
Remove any non-alphanumeric characters from the input phrase and convert it to lowercase.
Shuffle the characters in the phrase to create a randomized version of it.
Generate a random string of digits and symbols with a length of at least 6 and at most 10 characters.
Combine the shuffled phrase and the random string of digits and symbols to form the password.
The program should print the generated password to the console.

import random
import string

def password_from_phrase(phrase):
    # Remove any non-alphabetic characters and convert to lowercase
    phrase = ''.join(filter(str.isalpha, phrase)).lower()
    
    # Shuffle the characters in the phrase
    phrase_chars = list(phrase)
    random.shuffle(phrase_chars)
    shuffled_phrase = ''.join(phrase_chars)
    
    # Generate a random string of numbers and symbols
    num_symbols = random.randint(6, 10)
    symbols = ''.join(random.choices(string.punctuation, k=num_symbols))
    
    # Combine the shuffled phrase and symbols to form the password
    password = shuffled_phrase[:6] + symbols + shuffled_phrase[6:]
    
    return password