26.3k views
0 votes
Search the web to discover the 10 most common user-selected passwords, and store them in an array. Design a program that prompts a user for a password, and continue to prompt the user until the user has not chosen one of the common passwords.

1 Answer

6 votes

Answer:

userpassword = {"123456",

"password",

"123456789",

"12345678",

"12345",

"111111",

"1234567",

"sunshine",

"qwerty",

"abc123"}

#We define the function that prompts the user for a password

def user_passinput():

password = input("Choose enter a password: ")

return password

#Function that checks the password

def check_password():

count = 0

check_pass = user_passinput()

if check_pass in userpassword:

print("Yay!! you entered the correct password")

elif count <10:

count = count+1

print("Please try again")

user_passinput()

else:

print ("Maximum tries exceeded")

check_password()

Step-by-step explanation:

Using Python for this code, in the first line of the code, we list the dictionary of 10 most common passwords searched on the web. In line 12, we define the function that will demand the user to enter a password and return the value the user entered. Line 16 defines the function that checks if the password is common and prints to the screen either "Yay!! you entered the correct password", "Please try again" or "Maximum tries exceeded" depending on the condition that is satisfied. The last line of the code calls the check_password() function, which actually initiates the designed program.

User Granier
by
6.8k points