1G3QGXuESXBoxJAyxKaPHXkGs2onc2r3U8


SUBMITTED BY: Guest

DATE: Nov. 6, 2013, 5:07 p.m.

FORMAT: Python

SIZE: 2.3 kB

HITS: 928

  1. #!/usr/bin/env python
  2. # __copyright__ = Brandon Jackson
  3. # __license__ = GPL v2
  4. # This script evaluates passwords.
  5. import getpass, string, sys
  6. def testPassword():
  7. password_too_short, password_needs_uppercase, password_needs_lowercase, password_needs_number = True, True, True, True
  8. conditions_met = 1
  9. conditions_messages = {0: 'Your password is very weak.', 1: 'Your password is weak.', 2: 'Your password is average.', 3: 'Your password is nice.', 4: 'Your password is awesome!'}
  10. password = getpass.getpass("What's the password that you want to test?")
  11. if password in open('common_passwords.txt').read(): #if the password is not in the commonly used passwords file...
  12. print('Your password is common, therefore it is not safe at all.')
  13. sys.exit()
  14. if len(password) > 6: #if the password is greater than 6 characters...
  15. conditions_met + 1
  16. password_too_short = False
  17. for char in password:
  18. if char in string.ascii_uppercase: #if the password contains at least one uppercase letter...
  19. conditions_met + 1
  20. password_needs_uppercase = False
  21. if char in string.ascii_lowercase: #if the password contains at least one lowercase letter...
  22. conditions_met + 1
  23. password_needs_lowercase = False
  24. if char in string.digits: #if the password contains at least one number...
  25. conditions_met + 1
  26. password_needs_number = False
  27. if conditions_met == 0: print conditions_messages[0]
  28. if conditions_met == 1: print conditions_messages[1]
  29. if conditions_met == 2: print conditions_messages[2]
  30. if conditions_met == 3: print conditions_messages[3]
  31. if conditions_met == 4: print conditions_messages[4]
  32. if any((password_too_short, password_needs_uppercase, password_needs_lowercase, password_needs_number)):
  33. print('You can improve your password by...')
  34. if password_needs_lowercase: print(' -using lowercase letters.')
  35. if password_needs_uppercase: print(' -using uppercase letters.')
  36. if password_too_short: print(' -using more characters.')
  37. if password_needs_number: print(' -using numbers.')
  38. if __name__ == '__main__':
  39. testPassword()

comments powered by Disqus