Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 13, 2021 04:00 pm GMT

Simplest Python Random Password - with only 6 lines of code

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 stringimport randompassword_chars = string.ascii_letters + string.digits + string.punctuationlength = random.randint(12, 15)password = "".join([random.choice(password_chars) for _ in range(length)])print(password)

Or a single line password generator below:

import stringimport randomprint("".join([random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(random.randint(12, 15))]))

Original Link: https://dev.to/zsoltszakal/simplest-python-random-password-with-only-6-lines-of-code-4mnc

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To