Самый простой способ создания случайного пароля в Python.
- Импортная строка
- Импорт случайных
- Секреты импорта
- С строкой создать возможные символы
- создать пароль
- Распечатать пароль к консоли
import string import random import secrets password_chars = string.ascii_letters + string.digits + string.punctuation password = "".join([secrets.choice(password_chars) for i in range(random.randint(12, 15))]) print(password)
или сократить его еще больше:
import string import random import secrets password = "".join([secrets.choice(string.ascii_letters + string.digits + string.punctuation) for i in range(random.randint(12, 15))]) print(password)
Оригинал: “https://dev.to/zsoltszakal/the-most-simple-python-random-password-generator-only-6-lines-of-code-3j4h”