Question: # Predefined user dictionary with usernames and passwords users = { 'user 1 ' : 'password 1 2 3 ' , 'user 2 ' :

# Predefined user dictionary with usernames and passwords
users ={
'user1': 'password123',
'user2': 'letmein',
'user3': 'adminpass'
}
# Function to check login credentials
def login_system(username, password):
# Step 1: Check if the username exists in the dictionary
# Step 2: Compare the input password with the stored password
# Compare character by character (up to the shortest string length)
# Step 3: Check if the entire password matches
# Main part of the program
input_username = input("Enter your username: ")
# Track the number of attempts
attempts =0
max_attempts =5
# Allow up to 5 attempts to log in
# If username is not found, break the loop and stop further attempts
# If login is successful, break the loop
# Check if the account should be locked
Problem 3(40 Pts)4 input/output tests
Input username and password with stored credentials. Use a function to handle the login process, providing feedback on whether the login was successful or not. The user is allowed up to 5 login attempts. If the login fails after 5 attempts, the account will be locked. If the username is not found, the program should terminate immediately.
Requirements:
Create a function login_system(username, password) that:
Takes two arguments: a username and a password.
Checks if the username exists in the dictionary:
If the username is not found, return "Login failed: Username not found." and terminate the program immediately.
Compares the input password with the stored password:
If the passwords match exactly, return "Login successful!".
If only some characters match in the same positions, return how many characters match (e.g.,"3 characters match" or "1 character matches").
The program should allow up to 5 attempts for the user to log in.
After each failed attempt, provide feedback on how many characters matched.
If the user fails all 5 attempts, lock the account and display a message indicating that the account has been locked.
If the username is not found, terminate the program immediately without further attempts.
The program should stop once the user successfully logs in or after 5 failed attempts.
Example Interaction 1(Successful Login):
Enter your username: user1
Enter your password: pass123
Login failed: 4 characters match.
Enter your password: password123
Login successful!
Example Interaction 2(Failed Login and Account Lock):
Enter your username: user2
Enter your password: let
Login failed: 3 characters match.
Enter your password: letmeout
Login failed: 5 characters match.
Enter your password: wrongpassword
Login failed: 0 characters match.
Enter your password: letitgo
Login failed: 3 characters match.
Enter your password: openplease
Login failed: 0 characters match.
Account locked due to too many failed attempts.
Example Interaction 3:
Enter your username: user4
Enter your password: anypassword
Login failed: Username not found.
Notes:
The dictionary of usernames and passwords is predefined in the program.
The comparison should only count characters that match in the same positions.
Use a for loop to compare the password characters and count matches.
After each attempt, if the password doesn't match exactly, provide feedback on how many characters match in the correct position.
If the username is not found, the program should stop immediately without any password attempts.
If the username is found, allow up to 5 attempts for the user to log in.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!