4.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import os
  2. # Module to hide password input
  3. import getpass
  4. # Clear screen
  5. os.system("clear") # Mac or Linux
  6. #os.system("cls") # Windows
  7. # Get user input (will not show in terminal upon input)
  8. userInput = getpass.getpass("Input a password: ")
  9. # Reset criteria to unfulfilled
  10. letterCriteria = False
  11. numberCriteria = False
  12. lengthCriteria = False
  13. # Check length criteria (>= 12 characters long)
  14. # Store true or false in variable lengthCriteria
  15. lengthCriteria = len(userInput) >= 12
  16. # Iterate the password, character by character
  17. for i in userInput:
  18. # Test if character is alpha
  19. # If so, set letterCriteria to true (critera fulfilled)
  20. if i.isalpha():
  21. letterCriteria = True
  22. # Test if character is digit
  23. # If so, set numberCriteria to true (critera fulfilled)
  24. if i.isdigit():
  25. numberCriteria = True
  26. # Check if all critera is fulfilled (variables are True)
  27. if letterCriteria and numberCriteria and lengthCriteria:
  28. print("Password fulfilled all the criteria.")
  29. else:
  30. print("Password must contain at least one letter and one digit, and contain at least 12 characters.")