def zxcvbn(password, user_inputs=None): try: # Python 2 string types basestring = (str, unicode) except NameError: # Python 3 string types basestring = (str, bytes) if user_inputs is None: user_inputs = [] start = datetime.now() sanitized_inputs = [] for arg in user_inputs: if not isinstance(arg, basestring): arg = str(arg) sanitized_inputs.append(arg.lower()) ranked_dictionaries = matching.RANKED_DICTIONARIES ranked_dictionaries['user_inputs'] = matching.build_ranked_dict( sanitized_inputs) matches = matching.omnimatch(password, ranked_dictionaries) result = scoring.most_guessable_match_sequence(password, matches) result['calc_time'] = datetime.now() - start attack_times = time_estimates.estimate_attack_times(result['guesses']) for prop, val in attack_times.items(): result[prop] = val result['feedback'] = feedback.get_feedback(result['score'], result['sequence']) return result
def test_omnimatch(): assert matching.omnimatch('') == [], "doesn't match ''" password = '******' matches = matching.omnimatch(password) for [pattern_name, [i, j]] in [ ['dictionary', [0, 6]], ['dictionary', [7, 15]], ['date', [16, 23]], ['repeat', [24, 27]], ]: included = False for match in matches: if match['i'] == i and match['j'] == j \ and match['pattern'] == pattern_name: included = True msg = "for %s, matches a %s pattern at [%s, %s]" % (password, pattern_name, i, j) assert included, msg
def test_repeat_guesses(): for [token, base_token, repeat_count ] in [['aa', 'a', 2], ['999', '9', 3], ['$$$$', '$', 4], ['abab', 'ab', 2], ['batterystaplebatterystaplebatterystaple', 'batterystaple', 3]]: base_guesses = scoring.most_guessable_match_sequence( base_token, matching.omnimatch(base_token))['guesses'] match = { 'token': token, 'base_token': base_token, 'base_guesses': base_guesses, 'repeat_count': repeat_count, } expected_guesses = base_guesses * repeat_count msg = "the repeat pattern '#{token}' has guesses of #{expected_guesses}" assert scoring.repeat_guesses(match) == expected_guesses, msg
def password_strength(password, user_inputs=[]): start = time.time() matches = omnimatch(password, user_inputs) result = minimum_entropy_match_sequence(password, matches) result['calc_time'] = time.time() - start return result