File: __init__.py

package info (click to toggle)
python-zxcvbn 4.4.28-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 55,856 kB
  • sloc: python: 2,179; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 1,171 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from datetime import datetime

from . import matching, scoring, time_estimates, feedback

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