The most simple way to generate a random password in Python.
- import string
- import random
- import secrets
- with string create possible charachters
- create password
- print password to the console
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)
or to shorten it even more:
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)
Top comments (0)