Write a program to accept a string and check if it makes a strong password.
(A strong password should have at least 8 characters, one Upper case character, one lowercase character, a digit and one special character).
Sample Input:
Senior@Lab94
Sample Output
Strong password
(USING BLUE J). No spam or report..
Answers & Comments
Answer:
Certainly! Below is a simple Python program that uses regular expressions to check if a given string constitutes a strong password:
```python
import re
def is_strong_password(password):
# Check for at least 8 characters
if len(password) < 8:
return False
# Check for at least one uppercase letter
if not re.search(r'[A-Z]', password):
return False
# Check for at least one lowercase letter
if not re.search(r'[a-z]', password):
return False
# Check for at least one digit
if not re.search(r'\d', password):
return False
# Check for at least one special character
if not re.search(r'[!@#$%^&*(),.?":{}|<>]', password):
return False
return True
# Sample Input
password = input("Enter a password: ")
# Check and display result
if is_strong_password(password):
print("Strong password")
else:
print("Weak password")
```
Copy and paste this code into your BlueJ environment. When you run the program, it will prompt you to enter a password, and it will then output whether the provided password is strong or not based on the defined criteria.