Package: passwordgen
A generator for safe and random passwords defined by a user-defined pattern. The pattern allows for sequences of random digits, symbols, and characters, as well as whole words, with a multitude of options to customize the generated password.Installation$pipinstallpasswordgenOptions-h,--helpDisplay help menu-c,--copyWhenever a password is succesfully generated (in either singlue-use mode or interactive mode), the string will be copied to your clipboard (may require external libraries, depending on platform)-i,--interactiveLaunches in interactive mode, where passwords of the given pattern are continuously printed after each input, and if a valid pattern is given as input at any time, then the new pattern will be used going forward (enterqto exit)-wfile,--worddict=fileSets thewords.txtfile that is used as the dictionary for the generator when generating whole words. The parser goes line by line, using non-word characters to separate each word (this excludes hyphens and apostrophes, which are removed prior to parsing and the two sides of the word are merged) and a new, formattedwords.txtfile will be created (the previous version will be copied towords.txt.old)-lfile,--language=fileAttempts to use a pre-made words file (made from the dictionary of the specified language) and replaces the current words.txt file using that language’s words file, if it exists (if there is no default file for your language, please consider making your own file for your language and forking this project to include your language’s dictionary; go tohttps://github.com/nkrim/passwordgenfor more info)-R,--revertReverts the worddict file atwords.txtwith the backup file atwords.txt.old, if there is one. This is performed before a newwords.txtfile is generated if the-wcommand is used with thisHow to UsePattern BasicsA full pattern is comprised of one or more signifier expressions.  A signifier expression is composed of three parts, one or moresignifiers, zero or moreflags, and zero or onelength specifier.  All signifier expressions follows this basic pattern%'sig''flags'['length'](more complex examples will be shown after the following definitions).  All signifiers and flags are singular characters, while the length specifier can be defined as[n]wheren > 0or[n-N]wheren >= 0andN > 0andN >= n.SignifiersSignifiers can appear alone, to represent one character (or one word) from it’s respective pool of possibilities. Every signifier expression must contain at least one signifier, preceeded by a%character.Multiple SignifiersIf multiple signifiers are used for the same expression, they must be wrapped by curly-brackets along with their flags (but not their length specifier), for example:%{'sig1''sig2''sigN''flags'}['length']. When multiple signifiers are used, each character in the expression’s sequence is picked randomly from the pool of all available characters defined by the union of the sets of characters each signifier represents (therefore acsignifier used in a multiple signifier expression is redundant, ascis defined as including all charaters from the other signifier pools, unless used with the~flag to include the chance of using the pool of all characters).Note:TheWsignifiercannotbe included in an expression with multiple signifiers unless the~flag is present (raises an error).CharacterDefinitiondRandom digit(s)sRandom symbol(s)wRandom word character ([a-z])WRandom word (from dictionary, defaults to lowercase)cRandom character (excluding whitespace; word characters are of random capitalization)FlagsFlags are ways to manipulate the default action of each signifier. Certain flags can only interact with certain signifiers. If a flag is present but no signifiers that it can interact with are present, then it produces no effect.CharacterRelevant SignifiersDefinition~anyWhen used in an expresion with multiple signifiers, one signifier from the given set is randomly
chosen (without bias) to represent the sole signifier of the entire expression=d,s,w,cExpression will produce a sequence of a single random character repeated a number of times
(defined by it’s length specifier) from it’s pool of characters (defined by it’s signifiers)+w,WWord characters will be upper-case instead of their default of lowercase^w,WOne word character of the sequence will be uppercase (equivalent to+if=flag is present)+and^w,WWord character capitalization is randomized (this does not double the chance of getting a
character when using thecsignifier or a multiple signifier expression; when the=flag
is present there is a 50/50 chance between the whole sequence being lowercase or uppercase)Length SpecifierThe length specifier represents the length of the character sequence the signifier expression will produce. A length specifier can represent an explicit number, an inclusive range of numbers, or it can be absent. The length specifier, if present, is always surrounded by square brackets. The explicit specifier must satisfyn > 0wherenis the explicit length given, and the range specifier must satisfyn >= 0andN > 0andN >= nwherenis the lower bound of the range andNis the upper bound of the range. If any of these conditions are not satisfied, an error is raised and the program is terminated.Length Specifiers With theWSignifierThe generatordoes notpick the length randomly and then finds a random word of that length, but rather it groups up all words of acceptable length and picks randomly from that set, so whichever word-length is most frequent from that range, that would be the most probable result of the length of the word. Therefore, if part of the range exceeds the maximum word length, it is merely disregarded and the set to choose from is constructed from all available words with minimum length equal to the lower bound of the given range. If no words can be found satisfying the specified length (explicitly or via a range) a warning will be issued and the generator will choose a random word disregarding length.FormDefinition[n]The sequence will be explicitly of lengthn[n-N]The length of the sequence will fall between the range ofnandN, inclusively(absent)The sequence will be either a single character, or, for theWsignifier, will be a single word of random lengthSignifier Expression ExamplesA single random digit$passwordgen%d6A single random lowercase word$passwordgen%WpasswordA sequence of random lowercase word characters$passwordgen%w[4]dvzvA random lowercase word of length 5$passwordgen%W[5]cakesA sequence of random symbols with a length between 2 and 6$passwordgen%s[2-6]@$$#A sequence of a singular random digit, repeated between 4 and 6 times$passwordgen%d=[4-6]22222A random uppercase word$passwordgen%W+GENERATORA sequence of a singular random lowercase or uppercase character, repeated 3 times$passwordgen%w=^+[3]fffA random word with a length between 2 and 4, with one uppercase letter (the=flag has no effect)$passwordgen%W=^[2-4]gRipA random sequence of characters of length 8, with random capitalization$passwordgen%c+^[8]0es#V4uBA random sequence of digits and symbols of length 4$passwordgen%{ds}[4]1##8A random sequence of length 5 consisting entirely of either of word characters or digits$passwordgen%{wd~}[5]82535A sequence of a singular random lowercase or uppercase word character or symbol, repeated 7 times$passwordgen%{ws=^+}[7]GGGGGGGSame as above, except the chance between choosing a word character and a symbol is now equal because of the~flag, where previously the chance was weighted by the number of word characters vs the number of symbols$passwordgen%{ws=^+~}[7]$$$$$$$ContributingAdding languages’ dictionariesIf you could not find a particular language in the list of default language dictionaries (which can be used as presets word files for generating random words by using the-lflag with a valid language name) you can contribue to this project by adding your favorite languages! Please note though that, in it’s current form, passwordgen only supports basic alpha-numeric characters, so whichever language you wish to add should be able to be properly represented by this alphabet.You can contribute your language’s dictionary by following these steps:Fork this project’s github repository (https://github.com/nkrim/passwordgen)Find or create a file (with any formatting) with all (or as many as makes practical sense) of words from the language you wish to add (ensure that all characters in the words are basic alphabetic characters with no accents, aka ‘ç’ should be changed to ‘c’ and ‘é’ to ‘é’, though hyphens and apostrophes are removed prior to parsing by the program so those can be left in)Pre-format the file so it can be quickly loaded in at the user’s request. If you have passwordgen installed you can do this by runningpython-c"from passwordgen.worddict import WordDictionary;print(WordDictionary.parse('<path_to_your_source_file>'))"> <path_to_your_output_file>with the appropriate subsititions, or if you do not have passwordgen installed, you can do the same command from the root directory of this project by replacingpasswordgenwithsrcMove the formatted dictionary file into the directorysrc/words/defaultswithin this project, and ensure that the file’s name is the<language_name>.txtwhere<language_name>islowercaseand is the name of the language within its own language (i.e. “deutsch” instead of “german”, or “francais” intead of “french”)Push your new language file(s) to your fork, and make a pull requst so that it can be reviewed and hopefully added to the projectThank you for contributing n_n