Simplest Python Random Password – with only 6 lines of code

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

pass…


This content originally appeared on DEV Community and was authored by Zsolt Szakal

The most simple way to generate a random password in Python.

  1. import string
  2. import random
  3. with string create possible charachters
  4. with random generate a random number
  5. create password
  6. 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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Simplest Python Random Password – with only 6 lines of code." Zsolt Szakal | Sciencx - Saturday March 13, 2021, https://www.scien.cx/2021/03/13/simplest-python-random-password-with-only-6-lines-of-code/
HARVARD
Zsolt Szakal | Sciencx Saturday March 13, 2021 » Simplest Python Random Password – with only 6 lines of code., viewed ,<https://www.scien.cx/2021/03/13/simplest-python-random-password-with-only-6-lines-of-code/>
VANCOUVER
Zsolt Szakal | Sciencx - » Simplest Python Random Password – with only 6 lines of code. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/13/simplest-python-random-password-with-only-6-lines-of-code/
CHICAGO
" » Simplest Python Random Password – with only 6 lines of code." Zsolt Szakal | Sciencx - Accessed . https://www.scien.cx/2021/03/13/simplest-python-random-password-with-only-6-lines-of-code/
IEEE
" » Simplest Python Random Password – with only 6 lines of code." Zsolt Szakal | Sciencx [Online]. Available: https://www.scien.cx/2021/03/13/simplest-python-random-password-with-only-6-lines-of-code/. [Accessed: ]
rf:citation
» Simplest Python Random Password – with only 6 lines of code | Zsolt Szakal | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.