92.9k 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 continues to prompt the user until the user has not chosen one of the common passwords. Ensure that you store their password and can add that to the list so they cannot choose that password when they must change their password in the future.

User David Eyk
by
4.0k points

1 Answer

3 votes

Answer:

passwords = ["123456", "123456789", "qwerty", "password", "111111", "12345678", "abc123", "1234567", "password1", "12345"]

used_passwords = []

while True:

password = input("Choose a password: ")

if password in passwords:

print("You must not choose a common password!")

continue

elif password in used_passwords:

print("You used this password before. Choose a new one.")

continue

else:

used_passwords.append(password)

break

Step-by-step explanation:

*The code is in Python.

Initialize the passwords array with 10 most common user-selected passwords

Initialize the used_passwords array as empty

Create an infinite while loop. Inside the loop, ask the user to choose a password. Check if entered password is in the passwords or not. If it is, print a warning and ask the user to choose again using continue statement. If the entered password is in the used_passwords, print a warning message and ask the user to choose again using continue statement. If the previous conditions are not satisfied, it means the password is valid. Add the password to the used_passwords array and stop the loop using break statement.

User Nathan Osman
by
4.9k points