Skip to content

mk-pass

mk_pass.PasswordRequirements

Bases: NamedTuple

A structure to describe password requirements.

length class-attribute instance-attribute

length: int = 16

decimal class-attribute instance-attribute

decimal: int = 1

specials class-attribute instance-attribute

specials: int = 1

first_is_letter class-attribute instance-attribute

first_is_letter: bool = True

allow_repeats class-attribute instance-attribute

allow_repeats: bool = False

validate

validate() -> PasswordRequirements

Validates the instance's values.

This returns a mutated clone of the instance where the values satisfy "sane minimum requirements" suitable for any password.

The phrase "sane minimum requirements" implies

  1. length is not less than 10
  2. To avoid repetitions, length is not more than
    • 52 if only letters (no decimal integers or special characters) are used
    • 62 if only letters and decimal integers are used
    • 68 if only letters and special characters are used
    • 78 if letters, decimal integers, and special characters are used
    • 65535 if repeated characters are allowed
  3. specials character count does not overrule the required number of
    • letters (2; 1 uppercase and 1 lowercase)
    • decimal integers (if decimal is specified as non-zero value)
  4. decimal character count does not overrule the required number of
    • letters (2; 1 uppercase and 1 lowercase)
    • special characters (if specials is specified as non-zero value)
Note

If this function finds a conflict between the specified number of specials characters and decimal, then decimal integers takes precedence.

For example:

>>> from comp_gen_pass import PasswordRequirements
>>> req = PasswordRequirements(length=16, specials=16, decimal=16)
>>> req
PasswordRequirements { length: 16, decimal: 16, specials: 16, first_is_letter: true }
>>> req.validate()
PasswordRequirements { length: 16, decimal: 13, specials: 1, first_is_letter: true }

mk_pass.generate_password

generate_password(config: PasswordRequirements) -> str

Generate a password given the constraints specified by config.

This function will invoke PasswordRequirements.validate() to ensure basic password requirements are met.

mk_pass.main

main() -> None

The function used as an entrypoint for the executable script.

This function takes no parameters because they are parsed directly from sys.argv.