Парольный Ниндзя защитникоус

Python
import random
import string

def generate_password(length, include_letters, include_digits, include_symbols):
    characters = ''
    
    if include_letters:
        characters += string.ascii_letters  # Буквы
    if include_digits:
        characters += string.digits  # Цифры
    if include_symbols:
        characters += string.punctuation  # Специальные символы
        
    if not characters:
        return "Вы должны выбрать хотя бы один тип символов."

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

def view_passwords(passwords):
    if passwords:
        print("Сохраненные пароли:")
        for password in passwords:
            print(password)
    else:
        print("Нет сохраненных паролей.")

saved_passwords = []

while True:
    action = input("Выберите действие: (1) Сгенерировать пароль, (2) Посмотреть сохраненные пароли, (3) Выйти: ")
    
    if action == '1':
        length = int(input("Сколько символов должен содержать ваш пароль? "))
        
        if length <= 0:
            print("Длина пароля должна быть больше 0.")
            continue
        
        include_letters = input("Включать буквы? (y/n): ").lower() == 'y'
        include_digits = input("Включать цифры? (y/n): ").lower() == 'y'
        include_symbols = input("Включать специальные символы? (y/n): ").lower() == 'y'

        password = generate_password(length, include_letters, include_digits, include_symbols)
        print(f"Ваш сгенерированный пароль: {password}")

        save_choice = input("Хотите сохранить этот пароль? (y/n): ").lower()
        if save_choice == 'y':
            saved_passwords.append(password)
            print("Пароль сохранен.")

    elif action == '2':
        view_passwords(saved_passwords)

    elif action == '3':
        break
    
    else:
        print("Некорректный ввод, попробуйте еще раз.")
Inimitable timur.nurgaliev
Sign in to react
Uploaded Jul 3, 2026

Генератор пароль и код