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
'user: 'password
'user: 'letmein',
'user: 'adminpass'
# Function to check login credentials
def loginsystemusername password:
# Step : Check if the username exists in the dictionary
# Step : Compare the input password with the stored password
# Compare character by character up to the shortest string length
# Step : Check if the entire password matches
# Main part of the program
inputusername inputEnter your username:
# Track the number of attempts
attempts
maxattempts
# Allow up to 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 Pts inputoutput 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 login attempts. If the login fails after attempts, the account will be locked. If the username is not found, the program should terminate immediately.
Requirements:
Create a function loginsystemusername 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 eg characters match" or character matches"
The program should allow up to attempts for the user to log in
After each failed attempt, provide feedback on how many characters matched.
If the user fails all 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 failed attempts.
Example Interaction Successful Login:
Enter your username: user
Enter your password: pass
Login failed: characters match.
Enter your password: password
Login successful!
Example Interaction Failed Login and Account Lock:
Enter your username: user
Enter your password: let
Login failed: characters match.
Enter your password: letmeout
Login failed: characters match.
Enter your password: wrongpassword
Login failed: characters match.
Enter your password: letitgo
Login failed: characters match.
Enter your password: openplease
Login failed: characters match.
Account locked due to too many failed attempts.
Example Interaction :
Enter your username: user
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 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
