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 39 40 41 42 43 44
|
#!/usr/bin/env python3
"""Check the complexity of a password.
PYTHON_ARGCOMPLETE_OK
"""
from string import ascii_lowercase, ascii_uppercase, digits, punctuation
from milc import cli
from milc.questions import password
@cli.entrypoint('Check the complexity of a password.')
def main(cli):
c_lower = 0
c_upper = 0
c_digits = 0
c_punctuation = 0
c_other = 0
pw = password('Password to check:')
if not pw:
cli.log.error('No password provided!')
return 1
for char in pw:
if char in ascii_lowercase:
c_lower += 1
elif char in ascii_uppercase:
c_upper += 1
elif char in digits:
c_digits += 1
elif char in punctuation:
c_punctuation += 1
else:
c_other += 1
num_types = (c_lower > 0) + (c_upper > 0) + (c_digits > 0) + (c_punctuation > 0) + (c_other > 0)
cli.log.info('Found %d characters in the password!', len(pw))
cli.log.info('Found characters in %d different character classes!', num_types)
return 0
if __name__ == '__main__':
exit(cli())
|