#! /usr/bin/env python3 import re, sys if len(sys.argv)<2: print('usage: strongPassword [password] tests whether the password is at least 8 characters, contains both upper and lowercase, and has at least one digit/symbol, OR consists of at least 3 words of 4 letters each, containing both upper and lower case.') sys.exit() def checkShortPassword(password): if len(password)<8: return false hasLower = re.search('[a-z]', password) hasCaps = re.search('[A-Z]', password) hasDigitOrSymbol = re.search('[\d]|[\W_\s]', password) # return hasLower and hasCaps and hasDigitOrSymbol def checkLongPassword(password): has3Words = re.match('\s*\S+(?:\s+\S+){3,}', password) hasLower = re.search('[a-z]', password) hasCaps = re.search('[A-Z]', password) return has3Words and hasLower and hasCaps password = sys.argv[1] if checkLongPassword(password) or checkShortPassword(password): print('password is strong') else: print('password is weak!')