Python Cyber Security - Check password strength
Python Cyber Security: Exercise-3 with Solution
Write a Python program to check if a password meets the following criteria:
At least 8 characters long and
Contains at least one uppercase letter, one lowercase letter, one digit, and one special character (!, @, #, $, %, or &)
If the password meets the criteria, print a message that says "Valid Password." If it doesn't meet the criteria, print a message that says "Password does not meet requirements."
Sample Solution:
Python Code:
# Solution to Exercise 3
import re
def validate_password(password):
# Check if the password has at least 8 characters
if len(password) < 8:
return False
# Check if the password contains at least one uppercase letter
if not re.search(r'[A-Z]', password):
return False
# Check if the password contains at least one lowercase letter
if not re.search(r'[a-z]', password):
return False
# Check if the password contains at least one digit
if not re.search(r'\d', password):
return False
# Check if the password contains at least one special character
if not re.search(r'[!@#$%^&*(),.?":{}|<>]', password):
return False
# If all the conditions are met, the password is valid
return True
password = input("Input your password: ")
is_valid = validate_password(password)
if is_valid:
print("Valid Password.")
else:
print("Password does not meet requirements.")
Sample Output:
Input your password: Aji1#der Valid Password. Input your password: A123d$%h Valid Password. Input your password: A12&ki1 Password does not meet requirements. Input your password: KI342$&H Password does not meet requirements.
Flowchart:

Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Generate random passwords of specified length.
Next: Generate random passwords of specified length.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Python: Tips of the Day
Get Current Process Id:
import os os.getpid()
21423
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook