#!/usr/bin/env python # __copyright__ = Brandon Jackson # __license__ = GPL v2 # This script evaluates passwords. import getpass, string, sys def testPassword(): password_too_short, password_needs_uppercase, password_needs_lowercase, password_needs_number = True, True, True, True conditions_met = 1 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!'} password = getpass.getpass("What's the password that you want to test?") if password in open('common_passwords.txt').read(): #if the password is not in the commonly used passwords file... print('Your password is common, therefore it is not safe at all.') sys.exit() if len(password) > 6: #if the password is greater than 6 characters... conditions_met + 1 password_too_short = False for char in password: if char in string.ascii_uppercase: #if the password contains at least one uppercase letter... conditions_met + 1 password_needs_uppercase = False if char in string.ascii_lowercase: #if the password contains at least one lowercase letter... conditions_met + 1 password_needs_lowercase = False if char in string.digits: #if the password contains at least one number... conditions_met + 1 password_needs_number = False if conditions_met == 0: print conditions_messages[0] if conditions_met == 1: print conditions_messages[1] if conditions_met == 2: print conditions_messages[2] if conditions_met == 3: print conditions_messages[3] if conditions_met == 4: print conditions_messages[4] if any((password_too_short, password_needs_uppercase, password_needs_lowercase, password_needs_number)): print('You can improve your password by...') if password_needs_lowercase: print(' -using lowercase letters.') if password_needs_uppercase: print(' -using uppercase letters.') if password_too_short: print(' -using more characters.') if password_needs_number: print(' -using numbers.') if __name__ == '__main__': testPassword()