Python program to check the validity of username and password input by users
Question
Python program to check the validity of username and password input by users
Solution
Sure, here is a simple Python program that checks the validity of a username and password:
def check_validity(username, password):
# Define the criteria for a valid username and password
valid_username = "admin"
valid_password = "1234"
# Check if the input username and password match the valid ones
if username == valid_username and password == valid_password:
return "Access granted"
else:
return "Access denied"
# Test the function
username = input("Enter your username: ")
password = input("Enter your password: ")
print(check_validity(username, password))
In this program, the function check_validity takes a username and password as input and checks if they match the predefined valid username and password. If they match, the function returns "Access granted". If they don't match, the function returns "Access denied".
The last three lines of the program are used to test the function. They ask the user to input a username and password, and then call the check_validity function with these inputs. The result is then printed to the console.
Please note that this is a very basic program and doesn't include any security measures like password hashing or encryption. It's also not recommended to hard-code valid usernames and passwords into your program like this in a real-world application.
Similar Questions
Develop a Python script to simulate a basic user authentication system using if-else statementsand logical operators. The script should prompt the user for a username and password and validatethem against predefined credentials
Write a python program to accept the username "Admin" asthe default argument and password 123 entered by the user toallow login into the system using function
A student is writing a program that requires a user to create a password when they register a new account. To verify the password, the program requires the user to confirm the password they created by entering it a second time. The code for the routine is shown below.01 password = input('Please enter password:')02 storedPassword = password03 password = input('Confirm password:')04 if password != storedPassword then05 print('Passwords do not match')06 else07 print('Password accepted')08 endifState why the program only allows one attempt to match the passwords and outline how the program could be changed to enable the user to have up to three attempts to match the two passwords. You are not required to rewrite the code.[4]
Develop a Java program that creates a simple GUI application for a passwordvalidator. The program should allow users to input a password and check ifit meets certain criteria.
Develop a python function using regular expression for validating a password.Password should contain at least one capital letter, one number and one special character like @$!%*#?&Length of the password should be between 8 and 18.Sample Input:XdsE83&!2Sample Output:ValidSample Input:asDf#$Q$$Invalid
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.