Python Cyber Security - Check and print valid passwords from a file
5. Password File Validator
Write a Python program that reads a file containing a list of passwords, one per line. It checks each password to see if it meets certain requirements (e.g. at least 8 characters, contains both uppercase and lowercase letters, and at least one number and one special character). Passwords that satisfy the requirements should be printed by the program.
password.txt:
Pas1$Ku1 password password123 password123$ Password6#(% Germany#12 USA12^$# England0#
Sample Solution:
Python Code:
Sample Output:
Valid Password: Pas1$Ku1 Invalid Password: password Invalid Password: password123 Invalid Password: password123$ Valid Password: Password6#(% Valid Password: Germany#12 Invalid Password: USA12^$# Valid Password: England0#
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to read a file containing one password per line, validate each password against set criteria, and print only those that pass.
- Write a Python function that reads a text file of passwords, checks each for length and complexity, and returns a list of valid passwords.
- Write a Python script to process a password file, outputting a summary report with counts of valid and invalid passwords.
- Write a Python program to read a file of passwords, validate them, and then write the valid ones to a new file while logging the invalid ones.
Go to:
Previous: Function to suggest character substitutions for stronger passwords.
Next: Check if passwords in a list have been leaked in data breaches.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.