Question: 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.

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: 3 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: 6 characters match.
Enter your password: wrongpassword
Login failed: 2 characters match.
Enter your password: letitgo
Login failed: 4 characters match.
Enter your password: openplease
Login failed: 2 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!