toolrack.password

Password generation functions.

PasswordProfile defines a set of characters to use for generating password. It’s creating by passing a string with characters or character definitions encosed in curly braces (such as {alnum}, {num}, {alpha}), which are expanded to the corresponding set of characters.

For instance:

profile = PasswordProfile('{alpha}-_')
profile.generate(length=5)

yields a 5-chars password composed of letters, dashes and underscores.

toolrack.password.DEFAULT_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

letters, numbers and punctuation

Type:

Default character set

toolrack.password.DEFAULT_LENGTH = 10

Default password length

class toolrack.password.PasswordProfile(definition)

A password profile, specifying how to generate a random password.

CHAR_DEFS = (('alnum', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), ('alpha', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), ('num', '0123456789'), ('space', ' \t\n\r\x0b\x0c'), ('punct', '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'))
property chars

Return the set of characters used in generation.

generate(length=10)

Generate a random password.

toolrack.password.generate_password(chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~', length=10)

Generate a random password using the supplied characters.

Parameters:
  • chars (str) – a string with chars to choose from.

  • length (int) – number of chars for the password.