Q:

Generate a random Password which meets the following conditions using python programming

belongs to collection: Random Data Generation Exercises

0

Generate a random Password which meets the following conditions

  • Password length must be 10 characters long.
  • It must contain at least 2 upper case letters, 1 digit, and 1 special symbol.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import random
import string

def randomPassword():
    randomSource = string.ascii_letters + string.digits + string.punctuation
    password = random.sample(randomSource, 6)
    password += random.sample(string.ascii_uppercase, 2)
    password += random.choice(string.digits)
    password += random.choice(string.punctuation)

    passwordList = list(password)
    random.SystemRandom().shuffle(passwordList)
    password = ''.join(passwordList)
    return password

print ("Password is ", randomPassword())

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Calculate multiplication of two random float numbe... >>
<< Generate random String of length 5 using python pr...