CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

To secure your account, whether it be an email, online bank account or any other account, it is important that we use authentication. Use your programming expertise to create a program using user defined function named login that accepts userid and password as parameters (login(uid,pwd)) that displays a message “account blocked” in case of three wrong attempts. The login is successful if the user enters user ID as "ADMIN" and password as "St0rE@1". On successful login, display a message “login successful”.

Open in App
Solution

Points to consider:

i) As per the question, user-defined function login(uid,pwd)needs to be created which should display either “Login Successful” or “Account Blocked” after 3 wrong attempts. Therefore, a global variable should be used and its value should increase by 1 after every unsuccessful attempt.
ii) If the username and password are correct, the program should display “Login Successful” and terminate.
iii) Once the check for the username/password is complete and if the credentials are incorrect, the program should check for the counter value, and if ‘counter’ is more than 2, the program should display “Account Blocked” and exit, otherwise it should give the option to enter the username and password again.

The flow chart for the program can be drawn as follows:




Program:

counter = 0
def logintry():

##This function will ask for username and password from the user and then pass the entered value to the login function
username = input("Enter username: ")
password = input("Enter password: ")
login(username, password);
def login(uid,pwd):
global counter
if(uid=="ADMIN" and pwd =="St0rE@1"):
print("Login Successful")
return

#If username and password is correct the program will exit
else:
counter += 1
print("The username or password is incorrect")
if(counter>2):

# check counter value to see
# the no.of incorrect attempts
print("Account blocked")
return
else:

# Calling logintry() function to # start the process again
print("Try again")
logintry()

# Start the program by calling the function
logintry()


OUTPUT:

When Incorrect values are entered:

Enter username: user
Enter password: pwd
The username or password is incorrect
Try again

Enter username: uname
Enter password: password
The username or password is incorrect
Try again

Enter username: user
Enter password: password
The username or password is incorrect
Account blocked


When the correct values are entered:

Enter username: ADMIN
Enter password: St0rE@1
Login Successful

flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Introduction to e-Business
BUSINESS STUDIES
Watch in App
Join BYJU'S Learning Program
CrossIcon