Password Verification Project
Password Verification Project
Project to Practice Python
The aim of this mini project to practice Python, is to write a function that simulates the password verification process for a login page. The program should prompt the user to enter a password twice and then perform the following checks:
1) Verify that the two passwords entered by the user are identical.
2) Check if the password meets the security requirements defined by the administration:
– The password must have more than 8 characters.
– The first character of the password must be an uppercase letter.
– The password must contain at least one number and one special character (“!”, “?”, “-“, “_”).
Please ensure that the program displays appropriate messages to inform the user whether the password verification was successful or not.
Another great practice to work with user input, string validation, and condition checking in Python. Check here more projects to practice Python.
Steps
- Accept Input: Prompt the user to enter a password twice.
- Check Password Equality: Verify that the two passwords entered by the user are identical.
- Check Security Requirements: Validate that the password meets the security requirements defined by the administration.
- Display Verification Result: Inform the user whether the password verification was successful or not.
Source Code
import re
# Function to check if the password meets the security requirements
def is_valid_password(password):
# Check if the password has more than 8 characters
if len(password) < 8:
return False
# Check if the first character is an uppercase letter
if not password[0].isupper():
return False
# Check if there is at least one number and one special character
if not re.search(r"[0-9]", password) or not re.search(r"[!?\-_]", password):
return False
return True
# Accept user input for password
password1 = input("Enter your password: ")
password2 = input("Re-enter your password: ")
# Check if the two passwords are identical
if password1 != password2:
print("Passwords do not match.")
else:
# Check if the password meets the security requirements
if is_valid_password(password1):
print("Password verification successful. Your password meets the security requirements.")
else:
print("Password verification failed. Your password does not meet the security requirements.")
