Using Python, generate a random password which meets these rules and show five examples of the random passwords.
rules: password contains 6-20 characters, contain at least one lowercase letter, at least one uppercase letter, and at least one digit, must not contain three repeating characters in a row ("...aaa..." is weak, but "...aa...a..." is strong, assuming other conditions are met).
import random
import string
def get_random_password():
random_source = string.ascii_letters + string.digits
password = random.choice(string.ascii_lowercase)
password += random.choice(string.ascii_uppercase)
password += random.choice(string.digits)
print("please enter length of password in range 6 - 20")
length=int(input())
for i in range(length-4):
password += random.choice(random_source)
password_list = list(password)
random.SystemRandom().shuffle(password_list)
password = ''.join(password_list)
if(len(password)>=6 and len(password)<=20):
return password
else:
return "length was invalid"
print(get_random_password())
Please check the code. I hope it helps/
Get Answers For Free
Most questions answered within 1 hours.