Advertisements
Advertisements
प्रश्न
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 a 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 the user ID as "ADMIN" and the password as "St0rE@1". On successful login, display the message “login successful”.
थोडक्यात उत्तर
Advertisements
उत्तर
Points to consider:
- 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.
- If the username and password are correct, the program should display “Login Successful” and terminate.
- 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 a 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 the username and password are 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 Successfulshaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
