This content originally appeared on DEV Community and was authored by Zsolt Szakal
The most simple way to generate a random password in Python.
- import string
- import random
- with string create possible charachters
- with random generate a random number
- create password
- print password to the console
import string
import random
password_chars = string.ascii_letters + string.digits + string.punctuation
length = random.randint(12, 15)
password = "".join([random.choice(password_chars) for _ in range(length)])
print(password)
Or a single line password generator below:
import string
import random
print("".join([random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(random.randint(12, 15))]))
This content originally appeared on DEV Community and was authored by Zsolt Szakal
Zsolt Szakal | Sciencx (2021-03-13T16:00:26+00:00) Simplest Python Random Password – with only 6 lines of code. Retrieved from https://www.scien.cx/2021/03/13/simplest-python-random-password-with-only-6-lines-of-code/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.