• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bin/H11-Aug-2015-997441

lib/Crypt/H11-Aug-2015-2,300,0192,294,087

share/H03-May-2022-5555

t/H11-Aug-2015-264199

xscripts/H11-Aug-2015-8352

Build.PLH A D11-Aug-20151.7 KiB6158

INSTALLH A D11-Aug-2015107 65

LICENSEH A D11-Aug-20151.3 KiB2319

MANIFESTH A D11-Aug-20153 KiB4746

META.jsonH A D11-Aug-20154.8 KiB156155

META.ymlH A D11-Aug-20153.2 KiB114113

Makefile.PLH A D11-Aug-20151.3 KiB4240

READMEH A D11-Aug-201597 KiB2,2831,721

README

1NAME
2    `Crypt::HSXKPasswd' - A secure memorable password generator inspired by
3    Steve Gibson's Passord Haystacks (https://www.grc.com/haystack.htm), and
4    the famous XKCD password cartoon (https://xkcd.com/936/).
5
6VERSION
7    This documentation refers to `Crypt::HSXKPasswd' version 3.6.
8
9SYNOPSIS
10        use Crypt::HSXKPasswd;
11
12        #
13        # Functional Interface - a shortcut for generating single passwords
14        #
15
16        # generate a single password using the default word source, configuration,
17        # and random number generator
18        my $password = hsxkpasswd();
19
20        # the above call is simply a shortcut for the following
21        my $password = Crypt::HSXKPasswd->new()->password();
22
23        # this function passes all arguments on to Crypt::HSXKPasswd->new()
24        # so all the same customisations can be specified, e.g. specifying a
25        # config preset:
26        my $password = hsxkpasswd(preset => 'XKCD');
27
28        #
29        # Object Oriented Interface - recommended for generating multiple passwords
30        #
31
32        # create a new instance with the default dictionary, config, and random
33        # number generator
34        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new();
35
36        # generate a single password
37        my $password = $hsxkpasswd_instance->password();
38
39        # generate multiple passwords
40        my @passwords = $hsxkpasswd_instance->passwords(10);
41
42DESCRIPTION
43    A secure memorable password generator inspired by the wonderful XKCD
44    webcomic at http://www.xkcd.com/ and Steve Gibson's Password Haystacks
45    page at https://www.grc.com/haystack.htm. This is the Perl module that
46    powers https://www.xkpasswd.net.
47
48  PHILOSOPHY
49    More and more of the things we do on our computer require passwords, and
50    at the same time it seems we hear about organisations or sites losing
51    user database on every day that ends in a *y*. If we re-use our
52    passwords we expose ourself to an ever greater risk, but we need more
53    passwords than we can possibly remember or invent. Coming up with one
54    good password is easy, but coming up with one good password a week is a
55    lot harder, let alone one a day!
56
57    Obviously we need some technological help. We need our computers to help
58    us generate robust password and store them securely. There are many
59    great password managers out there to help us securely store and sync our
60    passwords, including commercial offerings and open-source projects. Many
61    of these managers also offer to generate random passwords for us,
62    usually in the form of a random string of meaningless letters numbers
63    and symbols. These kinds of nonsense passwords are certainly secure, but
64    they are often impractical.
65
66    Regardless of how good your chosen password manager is, there will
67    always be times when you need to type in your passwords, and that's when
68    random gibberish passwords become a real pain point. As annoying as it
69    is to have to glance over and back at a small cellphone screen to
70    manually type a gibberish password into a computer, that's nothing
71    compared to the annoyance of trying to communicate such a password to a
72    family member, friend, colleague or customer over the phone.
73
74    Surely it would be better to have passwords that are still truly random
75    in the way humans can't be, but are also human-friendly in the way
76    random gibberish never will be? This is the problem this module aims to
77    solve.
78
79    Rather than randomly choosing many letters, digits, and symbols from a
80    fairly small alphabet of possible characters, this library chooses a
81    small number of words from a large *alphabet* of possible words as the
82    basis for passwords. Words are easy to remember, easy to read from a
83    screen, easy to type, and easy to communicate over the telephone.
84
85    This module uses words to make up the bulk of the passwords it
86    generates, but it also adds carefully placed symbols and digits to add
87    security without making the passwords difficult to remember, read, type,
88    and speak.
89
90    In shot, this module is for people who prefer passwords that look like
91    this:
92
93        !15.play.MAJOR.fresh.FLAT.23!
94
95    to passwords that look like this:
96
97        eB8.GJXa@TuM
98
99  PASSWORD GENERATION ALGORITHM
100    This module always uses a simple five-step algorithm to generate
101    passwords, but each step can be customised, and many steps can be
102    skipped completely.
103
104    It's important to understand the algorithm before trying to create your
105    own custom configurations for this module.
106
107    The algorithm is broken in to the following steps:
108
109    1   Pick random words from the dictionary.
110
111    2   Apply transformations to the words.
112
113    3   Create pseudo-words made up for randomly chosen digits and add them
114        as the first and last words.
115
116    4   Insert a copy of the same symbol between each of the words and
117        pseudo-words. This symbol is referred to as the *separator
118        character*.
119
120    5   Pad the password with multiple instances of the same symbol front
121        and/or back. This symbol is referred to as the *padding character*.
122
123    You can visualise this process as follows:
124
125        correct horse batter staple
126        correct HORSE battery staple
127        25 correct HORSE battery staple 83
128        25*correct*HORSE*battery*staple*83
129        ++25*correct*HORSE*battery*staple*83++
130
131    Each of these steps can be customised in the following ways:
132
133    1   The number of words to be used, and the minimum and maximum lengths
134        of the words can be configured.
135
136    2   The case of the words can be modified in a number of ways, including
137        randomly choosing the case for each word.
138
139        It is also possible to specify so-called *133t-style* character
140        substitutions, e.g. replacing all occurrences of the letter `e' with
141        the digit `3', or all occurrences of the letter `s' with the symbol
142        `$'.
143
144    3   The number of digits to add as pseudo words to the front and back of
145        the password can be configured. A length of zero can be specified
146        for both to generate passwords without any randomly chosen digits.
147
148    4   The separator character can be specified directly, or it can be
149        randomly chosen from a list of symbols. It is also possible to
150        specify that no separator should be used.
151
152    5   The padding character can also be specified directly, or remotely
153        chosen from a list of possible symbols. Padding can also be disabled
154        completely. If padding is to be used it can be applied in two modes
155        - fixed, and adaptive.
156
157        With fixed padding a specified number of copies of the separator
158        character are added to the front and back of the password. The fixed
159        padding does not have to be symmetric.
160
161        With adaptive padding the required number of copies of the separator
162        character are added to the back of the password until it reaches a
163        specified length.
164
165  THE MATHS
166    Before examining the password strength of passwords generated with this
167    module we need to lay out the relatively simple maths underlying it all.
168
169    Maths Primer
170    A coin could be used as a very simple password generator. Each character
171    in the password would be the result of a single coin toss. If the coin
172    lands heads up, we add a `H' to our password, if it lands tails up, we
173    add a `T'.
174
175    If you made a one-letter password in this way there would only be two
176    possibilities, `H', or `T', or two permutations. If you made a
177    two-letter password in this way there would be four possible
178    combinations, or permutations, `HH', `HT', `TH', and `TT'. If you made a
179    three-character password in this way there would be 16 permutations, a
180    five character one would have 32 permutations, and so forth.
181
182    So, for a coin toss, which has two possible values for each character,
183    the formula for the number of permutations `P' for a given length of
184    password `L' is:
185
186        P = 2^L
187
188    Or, two to the power of the length of the password.
189
190    If we now swapped our coin for a dice, we would go from two possible
191    values per letter, to six possible values per letter. For one dice roll
192    there would be six permutations, for two there would be 36, for three
193    there would be 108 and so on.
194
195    This means that for a dice, the number of permutations can be calculated
196    with the formula:
197
198        P = 6^L
199
200    When talking about passwords, the set of possible symbols used for each
201    character in the password is referred to as the password's *alphabet*.
202    So, for the coin toss the alphabet was just `H' and `T', and for the
203    dice it was `1', `2', `3', `4', `5', and `6'. The actual characters used
204    in the alphabet make no difference to the strength of the password, all
205    that matters is the size of the alphabet, which we'll call `A'.
206
207    As you can probably infer from the two examples above, the formula for
208    the number of possible permutations `P' for a password of length `L'
209    created from an alphabet of size `A' is:
210
211        P = A^L
212
213    In the real world our passwords are generally made up of a mix of
214    letters, digits, and symbols. If we use mixed case that gives us 52
215    letters alone, then add in the ten digits from `0' to `9' and we're
216    already up to 62 possible characters before we even start on the array
217    of symbols and punctuation characters on our keyboards. It's generally
218    accepted that if you include symbols and punctuation, there are 95
219    characters available for use in randomly generated passwords. Hence, in
220    the real-world, the value for `A' is assumed to be 95. When you start
221    raising a number as big as 95 to even low powers the number of
222    permutations quickly rises.
223
224    A two character password with alphabet of 95 has 9025 permutations,
225    increasing the length to three characters brings that up to 857,375, and
226    so on. These numbers very quickly become too big to handle. For just an
227    8 character password we are talking about 6,634,204,312,890,625
228    permutations, which is a number so big most people couldn't say it (what
229    do you call something a thousand times bigger than a trillion?).
230
231    Because the numbers get so astronomically big so quickly, computer
232    scientists use bits of entropy to measure password strength rather than
233    the number of permutations. The formula to turn permutations into bits
234    of entropy `E' is very simple:
235
236        E = Log(2)P
237
238    In other words, the entropy is the log to base two of the permutations.
239    For our eight character example that equates to about 52 bits.
240
241    There are two approaches to increasing the number of permutations, and
242    hence the entropy, you can choose more characters, or, you can make the
243    alphabet you are choosing from bigger.
244
245    The Entropy of HSXKPasswd Passwords
246    Exactly how much entropy does a password need? That's the subject of
247    much debate, and the answer ultimately depends on the value of the
248    assets being protected by the password.
249
250    Two common recommendations you hear are 8 characters containing a mix of
251    upper and lower case letters, digits, and symbols, or 12 characters with
252    the same composition. These evaluation to approximately 52 bits of
253    entropy and 78 bits of entropy respectively.
254
255    When evaluating the entropy of passwords generated by this module, it
256    has to be done from two points of view for the answer to be meaningful.
257    Firstly, a best-case scenario - the attacker has absolutely no knowledge
258    of how the password was generated, and hence must mount a brute-force
259    attack. Then, secondly from the point of view of an attacker with full
260    knowledge of how the password was generated. Not just the knowledge that
261    this module was used, but a copy of the dictionary file used, and, a
262    copy of the configuration settings used.
263
264    For the purpose of this documentation, the entropy in the first
265    scenario, the brute force attack, will be referred to as the blind
266    entropy, and the entropy in the second scenario the seen entropy.
267
268    The blind entropy is solely determined by the configuration settings,
269    the seen entropy depends on both the settings and the dictionary file
270    used.
271
272    Calculating the bind entropy `Eb' is quite straightforward, we just need
273    to know the size of the alphabet resulting from the configuration `A',
274    and the minimum length of passwords generated with the configuration
275    `L', and plug those values into this formula:
276
277        Eb = Log(2)(A^L)
278
279    Calculating `A' simply involves determining whether or not the
280    configuration results in a mix of letter cases (26 or 52 characters),
281    the inclusion of at least one symbol (if any one is present, assume the
282    industry standard of a 33 character search space), and the inclusion of
283    at least one digit (10 character). This will result in a value between
284    26 and 95.
285
286    Calculating `L' is also straightforward. The one minor complication is
287    that some configurations result in a variable length password. In this
288    case, assume the shortest possible length the configuration could
289    produce.
290
291    The example password from the PHILOSOPHY section
292    (`!15.play.MAJOR.fresh.FLAT.23!') was generated using the preset
293    `WEB32'. This preset uses four words of between four and five letters
294    long, with the case of each word randomly set to all lower or all upper
295    as the basis for the password, it then chooses two pairs of random
296    digits as extra words to go front and back, before separating each word
297    with a copy of a randomly chosen symbol, and padding the front and back
298    of the password with a copy of a different randomly chosen symbol. This
299    results in passwords that contain a mix of cases, digits, and symbols,
300    and are between 27 and 31 characters long. If we add these values into
301    the formula we find that the blind entropy for passwords created with
302    this preset is:
303
304        Eb = Log(2)(95^27) = 163 bits
305
306    This is spectacularly secure! And, this is the most likely kind of
307    attack for a password to face. However, to have confidence in the
308    password we must also now calculate the entropy when the attacker knows
309    everything about how the password was generated.
310
311    We will calculate the entropy resulting from the same `WEB32' config
312    being used to generate a password using the sample library file that
313    ships with the module.
314
315    The number of permutations the attacker needs to check is purely the
316    product of possibly results for each random choice made during the
317    assembly of the password.
318
319    Lets start with the words that will form the core of the password. The
320    configuration chooses four words of between four and five letters long
321    from the dictionary, and then randomises their case, effectively making
322    it a choice from twice as many words (each word in each case).
323
324    The sample dictionary file contains 698 words of the configured length,
325    which doubles to 1396. Choosing four words from that very large alphabet
326    gives a starting point of `1396^4', or 3,797,883,801,856 permutations.
327
328    Next we need to calculate the permutations for the separator character.
329    The configuration specifies just nine permitted characters, and we
330    choose just one, so that equates to 9 permutations.
331
332    Similarly, the padding character on the end is chosen from 13 permitted
333    symbols giving 13 more permutations.
334
335    Finally, there are four randomly chosen digits, giving `10^4', or 10,000
336    permutations.
337
338    The total number of permutations is the product of all these
339    permutations:
340
341        Pseen = 3,797,883,801,856 * 9 * 13 * 10,000 = 2.77x10^17
342
343    Finally, we convert this to entropy by taking the base 2 log:
344
345        Eseen = Log(2)2.77x10^17 = ~57bits
346
347    What this means is that most probably, passwords generated with this
348    preset using the sample dictionary file are spectacularly more secure
349    than even 12 randomly chosen characters, and, that in the very unlikely
350    event that an attackers knows absolutely everything about how the
351    password was generated, it is still significantly more secure than 8
352    randomly chosen characters.
353
354    Because the exact strength of the passwords produced by this module
355    depend on the configuration and dictionary file used, the constructor
356    does the above math when creating an HSXKPasswd object, and throws a
357    warning if either the blind entropy falls below 78bits, or the seen
358    entropy falls below 52 bits.
359
360SUBROUTINES/METHODS
361  MODULE CONFIGURATION
362    It is possible to tweak the module's behaviour in certain areas by
363    updating the values contained within a set of module configuration keys.
364    The values associated with these keys can be accessed and updated via
365    the class function `module_config()'.
366
367        # get the current debug status
368        my $debug_status = Crypt::HSXKPasswd->module_config('DEBUG');
369
370        # configure the module to suppress all entropy warnings
371        Crypt::HSXKPasswd->module_config('ENTROPY_WARNINGS', 'NONE');
372
373    The following module configuration keys exist within the module:
374
375    *   `DEBUG' - A True/False value denoting whether or not the module
376        should print debug messages. The default is not to print debug
377        messages.
378
379        For more details see the DIAGNOSTICS section of this document.
380
381    *   `LOG_ERRORS' - A True/False value denoting whether or not errors
382        should be logged. The default is not to log.
383
384        For more details see the DIAGNOSTICS section of this document.
385
386    *   `LOG_STREAM' - the stream to which debug messages should be printed
387        if debugging is enabled, and log messages should be printed when
388        error logging is enabled. The default is to print to `STDERR'.
389
390        For more details see the DIAGNOSTICS section of this document.
391
392    *   `ENTROPY_MIN_BLIND' - the minimum allowable entropy against brute
393        force attacks in bits. The default is 78 bits.
394
395        For more details see the ENTROPY CHECKING section of this document.
396
397    *   `ENTROPY_MIN_SEEN' - the minimum allowable entropy against an
398        attacker with full knowledge. The default is 52 bits.
399
400        For more details see the ENTROPY CHECKING section of this document.
401
402    *   `ENTROPY_WARNINGS' - control the emission of entropy warnings. The
403        value must be one of `ALL', `BLIND', or `NONE'. The default value is
404        `ALL'.
405
406        For more details see the ENTROPY CHECKING section of this document.
407
408  CUSTOM DATA TYPES
409    This module uses a custom type library created with `Type::Library' for
410    data validation. It is important to know this for two reasons - firstly,
411    these custom types are mentioned in many error messages, and secondly
412    these custom types are available for developers to use in their own
413    code, either when utilising `Crypt::HSXKPasswd', or writing custom word
414    sources by extending `Crypt::HSXKPasswd::Dictionary', or when writing
415    custom random number generators by extending `Crypt::HSXKPasswd::RNG'.
416
417    Defined Types
418    *   `NonEmptyString' - a string containing at least one character.
419
420    *   `PositiveInteger' - a whole number greater than or equal to zero.
421
422    *   `NonZeroPositiveInteger' - a whole number greater than zero.
423
424    *   `TrueFalse' - a reasonable boolean value, specifically, `undef', and
425        empty string, or 0 to indicate false, and a 1 to indicate true.
426
427    *   `PerlPackageName' - string representing a valid Perl package name
428        like `Crypt::HSXKPasswd::Dictionary::NL'.
429
430    *   `Letter' - a string containing a single letter. Because this module
431        is Unicode-aware, it should be noted that a letter is defined as a
432        single Unicode grapheme with the Unicode property `Letter'. What
433        this means is that accented letters like `�' are considered valid,
434        as are ligatures like `�'.
435
436    *   `Symbol' - a string containing a single non-letter character.
437        Because this module is Unicode-aware, should be noted that a
438        non-letter character is defined as a single Unicode grapheme that
439        does not have the Unicode property `Letter'. What this means is that
440        neither letters, accented characters, nor ligatures can be used as
441        symbols, but just about every other Unicode character can, including
442        punctuation symbols, mathematical symbols, and even emoji!
443
444    *   `Word' - a string containing only letters (as defined by the type
445        `Letter'), and at least four long.
446
447    *   `SymbolAlphabet' - a symbol alphabet is a reference to an array that
448        contains at least two distinct symbols (as defined by the type
449        `Symbol'), and no values that are not symbols.
450
451    *   `WordLength' - a valid value when specifying the length of a word,
452        specifically, a whole number greater than or equal to four.
453
454    *   `ConfigKeyDefinition' - a valid configuration key definition. A
455        reference to a hash mapping `required' to a true/false value,
456        `expects' to a non-empty string, and `type' to a `Type::Tiny'
457        object.
458
459    *   `ConfigKeyName' - a valid configuration key name, see the
460        CONFIGURATION section of this document for a description of each
461        configuration key supported by this module. You can get a list of
462        valid configuration key names programatically by calling the
463        function `Crypt::HSXKPasswd-'defined_config_keys()>.
464
465    *   `ConfigKeyAssignment' - a mapping between a valid configuration key
466        name and a valid value for that configuration key.
467
468    *   `ConfigOverride' - a reference to hash containing one or more
469        configuration key assignments as defined by the type
470        `ConfigKeyAssignment'.
471
472    *   `Config' - a reference to a hash that contains a complete and valid
473        set of mappings between configuration key names and values. For a
474        config to be considered valid it must contain only valid valid
475        configuration key assignments as defined by the type
476        `ConfigKeyAssignment', must contain a configuration key assignment
477        for each required configuration key and all interdependencies
478        between the specified configuration key assignments must be
479        fulfilled.
480
481        See the CONFIG section of this document for a detailed description
482        of each of the defined configuration keys and their various
483        interdependencies.
484
485    *   `PresetDefinition' - a valid preset definition. A reference to a
486        hash mapping `description' to a non-empty string, and `config' to a
487        valid Config.
488
489    *   `PresetName' - a valid preset name, see the PRESETS section of this
490        document for a description of each preset supported by this module.
491        You can get a list of valid preset names programatically by calling
492        the function `Crypt::HSXKPasswd-'defined_presets()>.
493
494    Using the Custom Types
495    The library of custom types is defined in the package
496    `Crypt::HSXKPasswd::Types', and it is a standard `Type::Library' type
497    library containing `Type::Tiny' type definitions.
498
499    Useful Links:
500
501    *   The documentation for `Type::Tiny' -
502        http://search.cpan.org/perldoc?Type%3A%3ATiny
503
504    *   The documentation for `Type::Library' -
505        http://search.cpan.org/perldoc?Type%3A%3ALibrary
506
507    To use the bare type definitions listed above, import the module as
508    follows:
509
510        use Crypt::HSXKPasswd::Types qw( :types );
511
512    Each type listed above will now be imported, and become available as a
513    bare word. The `Type::Tiny' documentation provides a full list of
514    available functions, but the examples below illustrate some of the more
515    useful ones:
516
517        $is_valid = Letter->check('e'); # $is_valid = 1
518        $is_valid = Letter->check('-'); # $is_valid = undef
519        $err_msg = Letter->validate('e'); # $err_msg = undef
520        $err_msg = Letter->validate('-'); # $err_msg = "'-' is not a Letter ...
521                        # ... (must be a string containing exactly one letter)"
522
523    `Type::Library' automatically creates an `is_TypeName' function for each
524    type defined in the library. These are not imported by default. To
525    import them add the export tag `:is' to the `use' line. I would
526    recommend the following `use' line:
527
528        use Crypt::HSXKPasswd::Types qw( :types :is );
529
530    You can now do things like the following:
531
532        $is_valid = is_Letter('e'); # $is_valid = 1
533        $is_valid = is_Letter('-'); # $is_valid = undef
534
535    Each of the types listed above also contains a custom function using
536    `Type::Tiny''s new, and still officially experimental, `my_methods'
537    feature. The custom function is called `my_english', and can be used to
538    return an English description of the values considered valid by the
539    type, e.g.:
540
541        print Letter->my_english(); # prints: a string containing exactly one letter
542
543    As well as the named types listed above, there are also anonymous types
544    defined for each supported configuration key. These can be accessed
545    using the function `Crypt::HSXKPasswd-'config_key_definitions()>.
546
547    If declaring your own `Type::Tiny' types, you may also find the public
548    subroutine `Crypt::HSXKPasswd::Types::var_to_string()' useful - it will
549    turn anything passed as a scalar into a meaningful string, truncating
550    any resulting strings longer than 72 characters in nice way. All the
551    custom error messages in all the types defined in
552    `Crypt::HSXKPasswd::Types' make use of this subroutine.
553
554  CONFIGURATION
555    The module builds passwords using the following process.
556
557    First, a set of words are randomly chosen from the word source. Then,
558    two pseudo-words made of one or more digits may added before and/or
559    after the words from. Next, a separator character may be placed between
560    all the words (including the groups of digits), and one or more
561    occurrences of a padding symbol may be added front and/or back.
562
563    You can envisage the process as follows:
564
565        correct HORSE BATTERY staple
566        34 correct HORSE BATTERY staple 56
567        34-correct-HORSE-BATTERY-staple-56
568        !!34-correct-HORSE-BATTERY-staple-56!!
569
570    Many aspects of this password generation process are configurable. You
571    can control the length and number of words chosen, and what, if any,
572    case transformations should be applied to those words, and how accented
573    characters should be treated. How many, if any, digits should be added
574    front and back. What symbol, if any, should be used as a separator. And
575    finally how the password should be padded, if at all, and with what
576    symbol. Passwords can be padded to a given length, or by a given number
577    of symbols front and back.
578
579    The symbols used as the separator and for padding can be explicitly
580    specified, or the they can be randomly chosen from a given alphabet of
581    possible symbols. Both symbols can be randomly chosen from the same
582    alphabet, or from two separately specified alphabets.
583
584    Every instance of an HSXKPasswd password generator stores its
585    configuration as a set of name-value pairs, referred to as
586    *configuration keys* throughout this documentation.
587
588    Configurations can be specified either as a complete set of
589    configuration keys with values that together form a valid configuration,
590    as a named preset, or, as a named preset accompanied by a list of one or
591    more configuration keys with new values to override those specified by
592    the preset.
593
594    The module contains a preset called `DEFAULT', and this preset is used
595    if no configuration is specified. The function `default_config()' will
596    return a copy of this configuration as a reference to a hashtable.
597
598    For more details on how to specify configurations, see the documentation
599    for the constructor (the function `new()') below.
600
601    Password Generator Configuration Keys
602    Below is a list of all the configuration keys that can be used to
603    customise the password generation algorithm. Each configuration key is
604    accompanied by a description of what aspect of the algorithm they
605    control, and any validation rules that apply to the key.
606
607    Note that some keys are always required, and that there are dependencies
608    between keys. For examples, if you specify that the separator symbol
609    should be chosen at random, you must also specify an alphabet from which
610    the symbol should be randomly chosen.
611
612    *   `allow_accents' (optional) - if not specified, or if a falsy value
613        is specified, accents will be removed from letters in the generated
614        passwords. E.g. `�' becomes `e'. If a truthy value is specified,
615        accents will be preserved, and appear in the generated passwords.
616
617    *   `case_transform' (required) - the transformations, if any, that
618        should be applied to the words that appear in the generated
619        passwords. The value specified must be one of the following:
620
621        *   `ALTERNATE' - each alternate word will be converted to all upper
622            case and all lower case. The case of the first word is chosen at
623            random.
624
625        *   `CAPITALISE' - the first letter in every word will be converted
626            to upper case, all other letters will be converted to lower
627            case.
628
629        *   `INVERT' - the first letter in every word will be converted to
630            lower case, all other letters will be converted to upper case.
631
632        *   `LOWER' - all letters in all the words will be converted to
633            lower case. Use of this option is strongly discouraged for
634            security reasons.
635
636        *   `NONE' - the case of the letters that make up the words will not
637            be altered from how they were specified in the original word
638            source.
639
640        *   `RANDOM' - each word will be randomly converted to all upper
641            case or all lower case.
642
643        *   `UPPER' - all letters in all the words will be converted to
644            upper case. Use of this option is strongly discouraged for
645            security reasons.
646
647        The function `default_config()' returns a value of `CAPITALISE' for
648        this key.
649
650    *   `character_substitutions' (optional) - a reference to a hashtable
651        containing containing zero or more character substitutions to be
652        applied to the randomly chosen words when generating passwords. The
653        keys in the hashtable must be single letters. The substitutions can
654        contain multiple characters. Specifying one or more substitutions
655        with a length greater than one could lead to passwords being longer
656        than expected, and to entropy calculations being under estimated.
657        The module will issue a warning when such a config is loaded.
658
659    *   `num_words' (required) - the number of words to randomly choose from
660        the word source as the basis for the generated passwords.
661
662        The function `default_config()' returns a value of `3' for this key.
663
664    *   `pad_to_length' (conditionally required) - the length generated
665        passwords must be padded to when using adaptive padding, i.e. when
666        `padding_type' is set to `ADAPTIVE'). The value must be an integer
667        greater than or equal to 12. Lengths of less than 12 are not
668        permitted for security reasons.
669
670    *   `padding_alphabet' (optional) - this key is ignored unless the
671        configuration specifies that the padding character should be
672        randomly chosen, i.e. unless `padding_character' is set to `RANDOM'.
673
674        When the padding character is set to be randomly chosen, the module
675        will check for the presence of this key. If it is specified, the
676        padding character will be randomly chosen from the set of symbols
677        defined by this key. If this key is not set, the module will use the
678        set of symbols specified by the key `symbol_alphabet'. If neither
679        this key nor `symbol_alphabet' are specified, then the configuration
680        will be considered invalid.
681
682        If specified, this key must be a reference to an array of
683        single-character strings.
684
685    *   `padding_character' (conditionally required) - this key is unless
686        the key `padding_type' is set to `NONE'. It specifies the padding
687        symbol to be used when generating passwords.
688
689        If specified, they key's value must be a single character string, or
690        one of the following special values:
691
692        *   `RANDOM' - the character should be randomly chosen from the set
693            of characters specified by the key `padding_alphabet' or
694            `symbol_alphabet'. If specified, `padding_alphabet' takes
695            precedence over `symbol_alphabet'. If this value is specified
696            for `padding_character', and neither `padding_alphabet' nor
697            `symbol_alphabet' are specified, the configuration will be
698            considered invalid.
699
700        *   `SEPARATOR' - pad the password with the same symbol that is used
701            to separate the words. The key `padding_character' cannot be set
702            to `SEPARATOR' when the key `separator_character' is set to
703            `NONE'.
704
705        The function `default_config' return the value `RANDOM' for this
706        key.
707
708    *   `padding_characters_before' & `padding_characters_after'
709        (conditionally required) - both of these keys are required if the
710        key `padding_type' is set to `FIXED'.
711
712        These keys specify the number of padding symbols that should be
713        added to the front and back of the password.
714
715        Both keys require that the specified value be an integer greater
716        than or equal to zero.
717
718        The function `default_config()' returns a value of `2' for both of
719        these keys.
720
721    *   `padding_digits_before' & `padding_digits_after' (required) - the
722        number of random digits to include before and after the randomly
723        chosen words when generating passwords.
724
725        Both keys require that the specified value be an integer greater
726        than or equal to zero.
727
728        The function `default_config()' returns a value of `2' for both of
729        these keys.
730
731    *   `padding_type' (required) - the way in which padding symbols should
732        be added when generating passwords.
733
734        Only the following values are valid for this key:
735
736        *   `NONE' - do not add any padding symbols when generating
737            passwords.
738
739        *   `FIXED' - add an exactly specified number of copies of the
740            padding symbol to the front and back of generated passwords.
741
742            When they key `padding_type' is set to `FIXED', the three keys
743            `padding_character', `padding_characters_before' &
744            `padding_characters_after' become required.
745
746        *   `ADAPTIVE' - add no copies of the padding symbol will be added
747            to the front of the generated passwords, and copies of the
748            padding character will be added to the end of the generated
749            passwords until the total length of the password is equal to the
750            value specified for the key `pad_to_length'.
751
752            Note that If the password is longer than the value specified by
753            the key `pad_to_length' before any copies of the padding symbol
754            are added, the password will be truncated to the length
755            specified by the key `pad_to_length'.
756
757            When they key `padding_type' is set to `ADAPTIVE', the three
758            keys `padding_character', `padding_characters_before' &
759            `padding_characters_after' become required.
760
761        The function `default_config()' returns a value of `FIXED' for this
762        key.
763
764    *   `separator_alphabet' (optional) - this key is ignored unless the
765        configuration specifies that the separator character should be
766        randomly chosen, i.e. unless `separator_character' is set to
767        `RANDOM'.
768
769        When the separator character is set to be randomly chosen, the
770        module will check for the presence of this key. If it is specified,
771        the separator character will be randomly chosen from the set of
772        symbols defined by this key. If this key is not set, the module will
773        use the set of symbols specified by the key `symbol_alphabet'. If
774        neither this key nor `symbol_alphabet' are specified, then the
775        configuration will be considered invalid.
776
777        If specified, this key must be a reference to an array of
778        single-character strings.
779
780    *   `separator_character' (required) - the symbol to use to separate the
781        words when generating passwords.
782
783        The value specified for this key must be a single-character string,
784        or one of the following special values:
785
786        *   `NONE' - no separator character will be used. I.e. the words,
787            and the groups of digits before and after the words, if any,
788            will be directly joined together.
789
790            `RANDOM' - a single character will be randomly chosen from the
791            list of symbols specified by one of the keys
792            `separator_alphabet' or `symbol_alphabet'. If both keys are set,
793            `separator_alphabet' takes precedence.
794
795        The function `default_config()' returns a value of `RANDOM' for this
796        key.
797
798    *   `symbol_alphabet' (optional) - this key specifies a default alphabet
799        of symbols that can be used when either or both the separator
800        character and the padding character are set to be chosen at random.
801        I.e. when either or both of the keys `separator_character' and
802        `padding_character' are set to `RANDOM'.
803
804        Note that the keys `separator_alphabet' and `padding_alphabet' take
805        precedence over this key if specified.
806
807        The value specified for this key must be a reference to an array of
808        single-character strings.
809
810        The function `default_config()' returns a value of `['!', '@', '$',
811        '%', '^', '&', '*', '-', '_', '+', '=', ':', '|', '~', '?', '/',
812        '.', ';']' for this key.
813
814    *   `word_length_min' & `word_length_max' (required) - the minimum and
815        maximum length of the words that will form the basis of the
816        generated passwords.
817
818        The values specified for both keys must be integers greater than
819        three, and the value specified for `word_length_max' must be greater
820        than or equal to the value specified for `word_length_min'.
821
822        The function `default_config()' returns values of `4' and `8' for
823        these keys.
824
825  PRESETS
826    Below is a list of all the presets defined by this module.
827
828    This information can be accessed programatically using the functions
829    `defined_presets()', `presets_to_string()', `preset_description()', and
830    `preset_config()'.
831
832    *   `APPLEID' - a preset respecting the many prerequisites Apple places
833        on Apple ID passwords. Apple's official password policy cam be found
834        at the following URL: http://support.apple.com/kb/ht4232. Note that
835        Apple's knowledge base article omits to mention that passwords can't
836        be longer than 32 characters. This preset is also configured to use
837        only characters that are easy to type on the standard iOS keyboard,
838        i.e. those appearing on the letters keyboard (`ABC') or the numbers
839        keyboard `.?123', and not those on the harder to reach symbols
840        keyboard `#+='.
841
842        Sample Password:
843
844            -25,favor,MANY,BEAR,53-
845
846        Preset Definition:
847
848            {
849                padding_alphabet => [qw{- : . ! ? @ &}],
850                separator_alphabet => [qw{- : . @}, q{,}, q{ }],
851                word_length_min => 4,
852                word_length_max => 7,
853                num_words => 3,
854                separator_character => 'RANDOM',
855                padding_digits_before => 2,
856                padding_digits_after => 2,
857                padding_type => 'FIXED',
858                padding_character => 'RANDOM',
859                padding_characters_before => 1,
860                padding_characters_after => 1,
861                case_transform => 'RANDOM',
862                allow_accents => 0,
863            }
864
865    *   `DEFAULT' - the default configuration.
866
867        Sample Password:
868
869            ~~12:settle:SUCCEED:summer:48~~
870
871        Preset Definition:
872
873            {
874                symbol_alphabet => [qw{! @ $ % ^ & * - _ + = : | ~ ? / . ;}],
875                word_length_min => 4,
876                word_length_max => 8,
877                num_words => 3,
878                separator_character => 'RANDOM',
879                padding_digits_before => 2,
880                padding_digits_after => 2,
881                padding_type => 'FIXED',
882                padding_character => 'RANDOM',
883                padding_characters_before => 2,
884                padding_characters_after => 2,
885                case_transform => 'ALTERNATE',
886                allow_accents => 0,
887            }
888
889    *   `NTLM' - a preset for 14 character NTMLv1 (NTLM Version 1)
890        passwords. ONLY USE THIS PRESET IF YOU MUST! The 14 character limit
891        does not allow for sufficient entropy in scenarios where the
892        attacker knows the dictionary and config used to generate the
893        password. Use of this preset will generate a low entropy warning.
894
895        Sample Password:
896
897            0=mAYAN=sCART@
898
899        Preset Definition:
900
901            {
902                padding_alphabet => [qw{! @ $ % ^ & * + = : | ~ ?}],
903                separator_alphabet => [qw{- + = . * _ | ~}, q{,}],
904                word_length_min => 5,
905                word_length_max => 5,
906                num_words => 2,
907                separator_character => 'RANDOM',
908                padding_digits_before => 1,
909                padding_digits_after => 0,
910                padding_type => 'FIXED',
911                padding_character => 'RANDOM',
912                padding_characters_before => 0,
913                padding_characters_after => 1,
914                case_transform => 'INVERT',
915                allow_accents => 0,
916            }
917
918    *   `SECURITYQ' - a preset for creating fake answers to security
919        questions. This preset generates long nonsense sentences ending in
920        `.' `!' or `?'.
921
922        Sample 'Password':
923
924            Wales outside full month minutes gentle?
925
926        Preset Definition:
927
928            {
929                word_length_min => 4,
930                word_length_max => 8,
931                num_words => 6,
932                separator_character => q{ },
933                padding_digits_before => 0,
934                padding_digits_after => 0,
935                padding_type => 'FIXED',
936                padding_character => 'RANDOM',
937                padding_alphabet => [qw{. ! ?}],
938                padding_characters_before => 0,
939                padding_characters_after => 1,
940                case_transform => 'NONE',
941                allow_accents => 0,
942            }
943
944    *   `WEB16' - a preset for websites that don't allow passwords to be
945        longer than 16 characters. ONLY USE THIS PRESET IF YOU MUST! The 14
946        character limit does not allow for sufficient entropy in scenarios
947        where the attacker knows the dictionary and config used to generate
948        the password. Use of this preset will generate a low entropy
949        warning.
950
951        Sample Password:
952
953            tube+NICE+iron+02
954
955        Preset Definition:
956
957            {
958                symbol_alphabet => [qw{! @ $ % ^ & * - _ + = : | ~ ? / . ;}],
959                word_length_min => 4,
960                word_length_max => 4,
961                num_words => 3,
962                separator_character => 'RANDOM',
963                padding_digits_before => 0,
964                padding_digits_after => 2,
965                padding_type => 'NONE',
966                case_transform => 'RANDOM',
967                allow_accents => 0,
968            }
969
970    *   `WEB32' - a preset for websites that don't allow passwords to be
971        longer than 32 characters.
972
973        Sample Password:
974
975            +93-took-CASE-money-AHEAD-31+
976
977        Preset Definition:
978
979            {
980                padding_alphabet => [qw{! @ $ % ^ & * + = : | ~ ?}],
981                separator_alphabet => [qw{- + = . * _ | ~}, q{,}],
982                word_length_min => 4,
983                word_length_max => 5,
984                num_words => 4,
985                separator_character => 'RANDOM',
986                padding_digits_before => 2,
987                padding_digits_after => 2,
988                padding_type => 'FIXED',
989                padding_character => 'RANDOM',
990                padding_characters_before => 1,
991                padding_characters_after => 1,
992                case_transform => 'ALTERNATE',
993                allow_accents => 0,
994            }
995
996    *   `WIFI' - a preset for generating 63 character long WPA2 keys (most
997        routers allow 64 characters, but some only allow 63, hence the
998        somewhat unexpected length).
999
1000        Sample Password:
1001
1002            2736_ITSELF_PARTIAL_QUICKLY_SCOTLAND_wild_people_7441!!!!!!!!!!
1003
1004        Preset Definition:
1005
1006            {
1007                padding_alphabet => [qw{! @ $ % ^ & * + = : | ~ ?}],
1008                separator_alphabet => [qw{- + = . * _ | ~}, q{,}],
1009                word_length_min => 4,
1010                word_length_max => 8,
1011                num_words => 6,
1012                separator_character => 'RANDOM',
1013                padding_digits_before => 4,
1014                padding_digits_after => 4,
1015                padding_type => 'ADAPTIVE',
1016                padding_character => 'RANDOM',
1017                pad_to_length => 63,
1018                case_transform => 'RANDOM',
1019                allow_accents => 0,
1020            }
1021
1022    *   `XKCD' - a preset inspired by the original XKCD comic
1023        (http://xkcd.com/936/), but with some alterations to provide
1024        sufficient entropy to avoid low entropy warnings.
1025
1026        Sample Password:
1027
1028            quiet-children-OCTOBER-today-HOPE
1029
1030        Preset Definition:
1031
1032            {
1033                word_length_min => 4,
1034                word_length_max => 8,
1035                num_words => 5,
1036                separator_character => q{-},
1037                padding_digits_before => 0,
1038                padding_digits_after => 0,
1039                padding_type => 'NONE',
1040                case_transform => 'RANDOM',
1041                allow_accents => 0,
1042            }
1043
1044  FUNCTIONAL INTERFACE
1045    Although the package was primarily designed to be used in an
1046    object-oriented way, there is a functional interface too. The functional
1047    interface initialises an object internally and then uses that object to
1048    generate a single password. If you only need one password, this is no
1049    less efficient than the object-oriented interface, however, if you are
1050    generating multiple passwords it is much less efficient.
1051
1052    There is only a single function exported by the module:
1053
1054    hsxkpasswd()
1055        my $password = hsxkpasswd();
1056
1057    This function call is equivalent to the following Object-Oriented code:
1058
1059        my $password =  Crypt::HSXKPasswd->new()->password();
1060
1061    This function passes all arguments it receives through to the
1062    constructor, so all arguments that are valid in `new()' are valid here.
1063
1064    This function Croaks if there is a problem generating the password.
1065
1066    Note that it is inefficient to use this function to generate multiple
1067    passwords because the dictionary will be re-loaded, and the entropy
1068    stats re-calculated each time the function is called.
1069
1070  CONSTRUCTOR
1071        # create a new instance with the default dictionary, config, and random
1072        # number generator
1073        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new();
1074
1075        # the constructor takes optional named arguments, these can be used to
1076        # customise the word source, config, and random number source.
1077
1078        # create an instance that uses the UNIX words file as the word source
1079        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(
1080            dictionary => Crypt::HSXKPasswd::Dictionary::System->new()
1081        );
1082
1083        # create an instance that uses an array reference as the word source
1084        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(dictionary_list => $array_ref);
1085
1086        # create an instance that uses a dictionary file as the word source
1087        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(
1088            dictionary_file => 'sample_dict_EN.txt'
1089        );
1090
1091        # the class Crypt::HSXKPasswd::Dictionary::Basic can be used to aggregate
1092        # multiple array refs and/or dictionary files into a single word source
1093        my $dictionary = Crypt::HSXKPasswd::Dictionary::Basic->new();
1094        $dictionary->add_words('dict1.txt');
1095        $dictionary->add_words('dict2.txt');
1096        $dictionary->add_words($array_ref);
1097        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(dictionary => $dictionary);
1098
1099        # create an instance from the preset 'XKCD'
1100        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(preset => 'XKCD');
1101
1102        # create an instance based on the preset 'XKCD' with one customisation
1103        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(
1104            preset => 'XKCD',
1105            preset_override => {separator_character => q{ }}
1106        );
1107
1108        # create an instance from a config based on a preset
1109        # but with many alterations
1110        my $config = Crypt::HSXKPasswd->preset_config('XKCD');
1111        $config->{separator_character} = q{ };
1112        $config->{case_transform} = 'INVERT';
1113        $config->{padding_type} = "FIXED";
1114        $config->{padding_characters_before} = 1;
1115        $config->{padding_characters_after} = 1;
1116        $config->{padding_character} = '*';
1117        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(config => $config);
1118
1119        # create an instance from an entirely custom configuration
1120        my $config = {
1121            padding_alphabet => [qw{! @ $ % ^ & * + = : ~ ?}],
1122            separator_alphabet => [qw{- + = . _ | ~}],
1123            word_length_min => 6,
1124            word_length_max => 6,
1125            num_words => 3,
1126            separator_character => 'RANDOM',
1127            padding_digits_before => 2,
1128            padding_digits_after => 2,
1129            padding_type => 'FIXED',
1130            padding_character => 'RANDOM',
1131            padding_characters_before => 2,
1132            padding_characters_after => 2,
1133            case_transform => 'CAPITALISE',
1134        }
1135        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(config => $config);
1136
1137        # create an instance from an entire custom config passed as a JSON string
1138        # a convenient way to use configs generated using the web interface at
1139        # https://xkpasswd.net
1140        my $config = <<'END_CONF';
1141        {
1142         "num_words": 4,
1143         "word_length_min": 4,
1144         "word_length_max": 8,
1145         "case_transform": "RANDOM",
1146         "separator_character": " ",
1147         "padding_digits_before": 0,
1148         "padding_digits_after": 0,
1149         "padding_type": "NONE",
1150        }
1151        END_CONF
1152        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(config_json => $config);
1153
1154        # create an instance which uses /dev/urandom as the RNG
1155        # (only possible on Linux/Unix only systems)
1156        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(
1157            rng => Crypt::HSXKPasswd::RNG::DevUrandom->new();
1158        );
1159
1160        # create an instance which uses Random.Org as the random number generator
1161        # NOTE - this should be used sparingly, and only by the paranoid. If you
1162        # abuse this RNG your IP will get blacklisted on Random.Org. You must pass
1163        # a valid email address to the constructor for
1164        # Crypt::HSXKPasswd::RNG::RandomDorOrg because Random.Org's usage
1165        # guidelines request that all invocations to their API contain a contact
1166        # email in the useragent header, and this module honours that request.
1167        my $hsxkpasswd_instance = Crypt::HSXKPasswd->new(
1168            rng => Crypt::HSXKPasswd::RNG::RandomDorOrg->new('your.email@addre.ss');
1169        );
1170
1171    The constructor must be called via the package name.
1172
1173    If called with no arguments the constructor will use an instance of
1174    `Crypt::HSXKPasswd::Dictionary::EN' as the word source, the preset
1175    `DEFAULT', and an instance of the class `Crypt::HSXKPasswd::RNG::Basic'
1176    to generate random numbers.
1177
1178    The function accepts named arguments to allow for custom specification
1179    of the word source, config, and random number source.
1180
1181    Specifying Custom Word Sources
1182    Three named arguments can be used to specify a word source, but only one
1183    should be specified at a time. If multiple are specified, the one with
1184    the highest priority will be used, and the rest ignored. The variables
1185    are listed below in descending order of priority:
1186
1187    *   `dictionary' - an instance of a class that extends
1188        `Crypt::HSXKPasswd::Dictionary'.
1189
1190    *   `dictionary_list' - a reference to an array containing words as
1191        scalars.
1192
1193    *   `dictionary_file' - the path to a dictionary file. Dictionary files
1194        should contain one word per. Lines starting with a # symbol will be
1195        ignored. It is assumed files will be UTF-8 encoded. If not, a second
1196        named argument, `dictionary_file_encoding', can be used to specify
1197        another encoding.
1198
1199    Specifying Custom Password Generator Configurations
1200    Two primary named arguments can be used to specify the config the
1201    instance should use to generate passwords. Only one should be specified
1202    at a time. If multiple are specified, the one with the highest priority
1203    will be used, and the rest ignored. The variables are listed below in
1204    descending order of priority:
1205
1206    *   `config' - a valid config hashref.
1207
1208    *   `config_json' - a JSON string representing a valid config hashref.
1209
1210        This named argument provides a convenient way to use configs
1211        generated using the web interface at https://xkpasswd.net/. The
1212        Save/Load tab in that interface saves and loads configs in JSON
1213        format.
1214
1215    *   `preset' - a valid preset name. If this variable is used, then any
1216        desired config overrides can be passed as a hashref using the
1217        variable `preset_overrides'.
1218
1219    Specifying Custom Random Number Generators
1220    A custom RNG can be specified using the named argument `rng'. The passed
1221    value must be an instance of a class that extends
1222    `Crypt::HSXKPasswd::RNG' and overrides the function `random_numbers()'.
1223
1224  INSTANCE METHODS
1225    NOTE - all instance methods must be invoked on a Crypt::HSXKPasswd
1226    object or they will croak.
1227
1228    ->config()
1229        my $config = $hsxkpasswd_instance->config(); # getter
1230        $hsxkpasswd_instance->config($config_hashref); # setter
1231        $hsxkpasswd_instance->config($config_json_string); # setter
1232
1233    When called with no arguments the function returns a clone of the
1234    instance's config hashref.
1235
1236    When called with a single argument the function sets the config of the
1237    instance to a clone of the passed config. If present, the argument must
1238    be either a hashref containing valid config keys and values, or a JSON
1239    string representing a hashref containing valid config keys and values.
1240
1241    The function will croak if an invalid config is passed.
1242
1243    ->config_as_json()
1244        my $config_json_string = $hsxkpasswd_instance->config_as_json();
1245
1246    This function returns the content of the instance's loaded config
1247    hashref as a JSON string.
1248
1249    The output from this function can be loaded into the web interface at
1250    https://xkpasswd.net (using the load/save tab).
1251
1252    ->config_as_string()
1253        my $config_string = $hsxkpasswd_instance->config_as_string();
1254
1255    This function returns the content of the instance's loaded config
1256    hashref as a scalar string.
1257
1258    ->dictionary()
1259        my $dictionary_clone = $hsxkpasswd_instance->dictionary();
1260        $hsxkpasswd_instance->dictionary($dictionary_instance);
1261        $hsxkpasswd_instance->dictionary($array_ref);
1262        $hsxkpasswd_instance->dictionary('sample_dict_EN.txt');
1263        $hsxkpasswd_instance->dictionary('sample_dict_EN.txt', 'Latin1');
1264
1265    When called with no arguments this function returns a clone of the
1266    currently loaded dictionary which will be an instance of a class that
1267    extends `Crypt::HSXKPasswd::Dictionary'.
1268
1269    To load a new dictionary into an instance, call this function with
1270    arguments. The first argument argument can be an instance of a class
1271    that extends `Crypt::HSXKPasswd::Dictionary', a reference to an array of
1272    words, or the path to a dictionary file. If either an array reference or
1273    a file path are passed, they will be used to instantiate an instance of
1274    the class `Crypt::HSXKPasswd::Dictionary::Basic', and that new instance
1275    will then be loaded into the object. If a file path is passed, it will
1276    be assumed to be UTF-8 encoded. If not, an optional second argument can
1277    be passed to specify the file's encoding.
1278
1279    ->password()
1280        my $password = $hsxkpasswd_instance->password();
1281
1282    This function generates a random password based on the instance's loaded
1283    config and returns it as a scalar. The function takes no arguments.
1284
1285    The function croaks if there is an error generating the password. The
1286    most likely cause of and error is the random number generation,
1287    particularly if the loaded random generation function relies on a cloud
1288    service or a non-standard library.
1289
1290    ->passwords()
1291        my @passwords = $hsxkpasswd_instance->passwords(10);
1292
1293    This function generates a number of passwords and returns them all as an
1294    array.
1295
1296    The function uses `password()' to generate the passwords, and hence will
1297    croak if there is an error generating any of the requested passwords.
1298
1299    ->passwords_json()
1300        my $json_string = $hsxkpasswd_instance->passwords_json(10);
1301
1302    This function generates a number of passwords and returns them and the
1303    instance's entropy stats as a JSON string representing a hashref
1304    containing an array of passwords indexed by `passwords', and a hashref
1305    of entropy stats indexed by `stats'. The stats hashref itself is indexed
1306    by: `password_entropy_blind', `password_permutations_blind',
1307    `password_entropy_blind_min', `password_entropy_blind_max',
1308    `password_permutations_blind_max', `password_entropy_seen' &
1309    `password_permutations_seen'.
1310
1311    The function uses `passwords()' to generate the passwords, and hence
1312    will croak if there is an error generating any of the requested
1313    passwords.
1314
1315    ->rng()
1316        my $rng_instance = $hsxkpasswd_instance->rng();
1317        $hsxkpasswd_instance->rng($rng_instance);
1318
1319    When called with no arguments this function returns currently loaded
1320    Random Number Generator (RNG) which will be an instance of a class that
1321    extends `Crypt::HSXKPasswd::RNG'.
1322
1323    To load a new RNG into an instance, call this function with a single
1324    argument, an instance of a class that extends `Crypt::HSXKPasswd::RNG'.
1325
1326    ->stats()
1327        my %stats = $hsxkpasswd_instance->stats();
1328
1329    This function generates a hash containing stats about the instance
1330    indexed by the following keys:
1331
1332    *   `dictionary_contains_accents' - 1 if the filtered word list contains
1333        accented letters, 0 otherwise.
1334
1335    *   `dictionary_filter_length_min' & `dictionary_filter_length_max' -
1336        the minimum and maximum word lengths allowed by the dictionary
1337        filter (defined by config keys `word_length_min' and
1338        `word_length_max')
1339
1340    *   `dictionary_source' - the source of the word list loaded into the
1341        instance.
1342
1343    *   `dictionary_words_filtered' - the number of words loaded from the
1344        dictionary file that meet the criteria defined by the loaded config.
1345
1346    *   `dictionary_words_percent_available' - the percentage of the words
1347        in the dictionary file that are available for use with the loaded
1348        config.
1349
1350    *   `dictionary_words_total' - the total number of words loaded from the
1351        dictionary file.
1352
1353    *   `password_entropy_blind_min' - the entropy (in bits) of the shortest
1354        password the loaded config can generate from the point of view of a
1355        brute-force attacker.
1356
1357    *   `password_entropy_blind_max' - the entropy (in bits) of the longest
1358        password the loaded config can generate from the point of view of a
1359        brute-force attacker.
1360
1361    *   `password_entropy_blind' - the entropy (in bits) of the average
1362        length of passwords the loaded config can generate from the point of
1363        view of a brute-force attacker.
1364
1365    *   `password_entropy_seen' - the entropy (in bits) of passwords
1366        generated by the instance assuming the dictionary and config are
1367        known to the attacker.
1368
1369    *   `password_length_min' - the minimum length of passwords generated by
1370        the loaded config.
1371
1372    *   `password_length_max' - the maximum length of passwords generated by
1373        the loaded config.
1374
1375    *   `password_permutations_blind_min' - the number of permutations a
1376        brute-force attacker would have to try to be sure of cracking the
1377        shortest possible passwords generated by this instance. Because this
1378        number can be very big, it's returned as a `Math::BigInt' object.
1379
1380    *   `password_permutations_blind_max' - the number of permutations a
1381        brute-force attacker would have to try to be sure of cracking the
1382        longest possible passwords generated by this instance. Because this
1383        number can be very big, it's returned as a `Math::BigInt' object.
1384
1385    *   `password_permutations_blind' - the number of permutations a
1386        brute-force attacker would have to try to be sure of cracking an
1387        average length password generated by this instance. Because this
1388        number can be very big, it's returned as a `Math::BigInt' object.
1389
1390    *   `password_permutations_seen' - the number of permutations an
1391        attacker with a copy of the dictionary and config would need to try
1392        to be sure of cracking a password generated by this instance.
1393        Because this number can be very big, it's returned as a
1394        `Math::BigInt' object.
1395
1396    *   `passwords_generated' - the number of passwords this instance has
1397        generated.
1398
1399    *   `password_random_numbers_required' - the number of random numbers
1400        needed to generate a single password using the loaded config.
1401
1402    *   `randomnumbers_cached' - the number of random numbers currently
1403        cached within the instance.
1404
1405    *   `randomnumbers_cache_increment' - the number of random numbers
1406        generated at once to replenish the cache when it's empty.
1407
1408    *   `randomnumbers_source' - the class used by the instance to generate
1409        random numbers.
1410
1411    ->status()
1412        print $hsxkpasswd_instance->status();
1413
1414    Generates a string detailing the internal status of the instance. Below
1415    is a sample status string:
1416
1417        *DICTIONARY*
1418        Source: Crypt::HSXKPasswd::Dictionary::EN
1419        # words: 1425
1420        # words of valid length: 1194 (84%)
1421
1422        *CONFIG*
1423        case_transform: 'ALTERNATE'
1424        num_words: '3'
1425        padding_character: 'RANDOM'
1426        padding_characters_after: '2'
1427        padding_characters_before: '2'
1428        padding_digits_after: '2'
1429        padding_digits_before: '2'
1430        padding_type: 'FIXED'
1431        separator_alphabet: ['!', '$', '%', '&', '*', '+', '-', '.', '/', ':', ';', '=', '?', '@', '^', '_', '|', '~']
1432        separator_character: 'RANDOM'
1433        symbol_alphabet: ['!', '$', '%', '&', '*', '+', '-', '.', '/', ':', ';', '=', '?', '@', '^', '_', '|', '~']
1434        word_length_max: '8'
1435        word_length_min: '4'
1436
1437        *RANDOM NUMBER CACHE*
1438        Random Number Generator: Crypt::HSXKPasswd::RNG::Basic
1439        # in cache: 0
1440
1441        *PASSWORD STATISTICS*
1442        Password length: between 24 & 36
1443        Permutations (brute-force): between 2.91x10^47 & 1.57x10^71 (average 2.14x10^59)
1444        Permutations (given dictionary & config): 5.51x10^15
1445        Entropy (Brute-Force): between 157bits and 236bits (average 197bits)
1446        Entropy (given dictionary & config): 52bits
1447        # Random Numbers needed per-password: 9
1448        Passwords Generated: 0
1449
1450    ->update_config()
1451        $hsxkpasswd_instance->update_config({separator_character => '+'});
1452
1453    The function updates the config within an HSXKPasswd instance. A hashref
1454    with the config options to be changed must be passed. The function
1455    returns a reference to the instance to enable function chaining. The
1456    function will croak if the updated config would be invalid in some way.
1457    Note that if this happens the running config will not have been altered
1458    in any way.
1459
1460  CLASS METHODS
1461    NOTE - All class methods must be invoked via the package name, or they
1462    will croak.
1463
1464    clone_config()
1465        my $clone = Crypt::HSXKPasswd->clone_config($config);
1466
1467    This function must be passed a valid config hashref as the first
1468    argument or it will croak. The function returns a hashref.
1469
1470    config_key_definition()
1471        my %key_definition = Crypt::HSXKPasswd->config_key_definition($key_name);
1472
1473    A function to return the definition for a config key. The definition is
1474    returned as a hash indexed by the following keys:
1475
1476    *   `required' - 1 if the key is a required key, and 0 otherwise.
1477
1478    *   `type' - a `Type::Tiny' object representing the valid data type for
1479        the key.
1480
1481    *   `expects' - an English description of valid values for the key.
1482
1483    config_key_definitions()
1484        my %key_definitions = Crypt::HSXKPasswd->config_key_definitions();
1485
1486    A function to return definitions for all defined config keys as a hash
1487    indexed by config key names. Each definition is represented as a hash
1488    with the same keys as the hashes returned by the function
1489    `config_key_definition()'.
1490
1491    config_stats()
1492        my %stats = Crypt::HSXKPasswd->config_stats($config);
1493        my %stats = Crypt::HSXKPasswd->config_stats(
1494            $config,
1495            suppress_warnings => 1,
1496        );
1497
1498    This function requires one argument, a valid config hashref. It returns
1499    a hash of statistics about a given configuration. The hash is indexed by
1500    the following:
1501
1502    *   `length_min' - the minimum length a password generated with the
1503        given config could be.
1504
1505    *   `length_max' - the maximum length a password generated with the
1506        given config could be. (see caveat below)
1507
1508    *   `random_numbers_required' - the amount of random numbers needed to
1509        generate a password using the given config.
1510
1511    There is one scenario in which the calculated maximum length will not be
1512    reliably accurate, and that's when a character substitution with a
1513    length greater than 1 is specified, and `padding_type' is not set to
1514    `ADAPTIVE'. If the config passed contains such a character substitution,
1515    the length will be calculated ignoring the possibility that one or more
1516    extra characters could be introduced depending on how many, if any, of
1517    the long substitutions get triggered by the randomly chosen words. If
1518    this happens the function will also carp with a warning. Such warnings
1519    can be suppressed by passing an optional named argument
1520    `suppress_warnings' with the value `1'.
1521
1522    config_to_json()
1523        my $config_json_string = Crypt::HSXKPasswd->config_to_json($config);
1524
1525    This function returns a JSON representation of the passed config hashref
1526    as a scalar string.
1527
1528    The function must be passed a valid config hashref or it will croak.
1529
1530    config_to_string()
1531        my $config_string = Crypt::HSXKPasswd->config_to_string($config);
1532
1533    This function returns the content of the passed config hashref as a
1534    scalar string. The function must be passed a valid config hashref or it
1535    will croak.
1536
1537    default_config()
1538        my $config = Crypt::HSXKPasswd->default_config();
1539
1540    This function returns a hashref containing a config with default values.
1541
1542    This function can optionally be called with a single argument, a hashref
1543    containing keys with values to override the defaults with.
1544
1545        my $config = Crypt::HSXKPasswd->default_config({num_words => 3});
1546
1547    When overrides are present, the function will carp if an invalid key or
1548    value is passed, and croak if the resulting merged config is invalid.
1549
1550    This function is a shortcut for `preset_config()', and the two examples
1551    above are equivalent to the following:
1552
1553        my $config = Crypt::HSXKPasswd->preset_config('DEFAULT');
1554        my $config = Crypt::HSXKPasswd->preset_config('DEFAULT', {num_words => 3});
1555
1556    defined_config_keys()
1557        my @config_key_names = Crypt::HSXKPasswd->defined_config_keys();
1558
1559    This function returns the list of valid config key names as an array of
1560    strings.
1561
1562    defined_presets()
1563        my @preset_names = Crypt::HSXKPasswd->defined_presets();
1564
1565    This function returns the list of defined preset names as an array of
1566    strings.
1567
1568    distil_to_config_keys()
1569        my $dist_hashref = Crypt::HSXKPasswd->distil_to_config_keys($hashref);
1570
1571    This function takes a hashref as an argument, and returns a deep clone
1572    of that hashref containing only valid config keys with valid values.
1573
1574    By default the function silently drops keys that are not valid config
1575    keys, but issues a warning when dropping a key that is a valid config
1576    key, but contains an invalid value. The function can also issue warnings
1577    when dropping keys that are not valid config keys.
1578
1579    The warnings can be controlled with a pair of optional named arguments
1580    that can be added as a second argument:
1581
1582        # suppress all warnings
1583        my $dist_hashref = Crypt::HSXKPasswd->distil_to_config_keys(
1584            $hashref,
1585            suppress_warnings => 1,
1586        );
1587
1588        # emit warnings when dropping invalidly named keys
1589        my $dist_hashref = Crypt::HSXKPasswd->distil_to_config_keys(
1590            $hashref,
1591            warn_invalid_key_names => 1,
1592        );
1593
1594    distil_to_symbol_alphabet()
1595        my @unique_syms = Crypt::HSXKPasswd->distil_to_symbol_alphabet($arrayref);
1596        my @unique_syms = Crypt::HSXKPasswd->distil_to_symbol_alphabet(
1597            $arrayref,
1598            warn => 1,
1599        );
1600
1601    This function takes reference to an array of strings and returns a new
1602    array containing all the valid symbols from the referenced array. The
1603    valid symbols are de-duplicated before being returned.
1604
1605    By default the function silently skips over strings that are not valid
1606    symbols. The function can be made issue warnings each time a string is
1607    skipped by passing a named argument `warn' with a value of `1' (`0' can
1608    also be passed to explicitly disable warnings).
1609
1610    distil_to_words()
1611        my @valid_unique_words = Crypt::HSXKPasswd->distil_to_words($arrayref);
1612        my @valid_unique_words = Crypt::HSXKPasswd->distil_to_words(
1613            $arrayref,
1614            warn => 1,
1615        );
1616
1617    This function takes reference to an array of strings and returns a new
1618    array containing all the valid words from the referenced array. The
1619    valid words are de-duplicated before being returned.
1620
1621    By default the function silently skips over strings that are not valid
1622    words. The function can be made issue warnings each time a string is
1623    skipped by passing a named argument `warn' with a value of `1' (`0' can
1624    also be passed to explicitly disable warnings).
1625
1626    is_valid_config()
1627        # determine the validity
1628        my $is_ok = Crypt::HSXKPasswd->is_valid_config($config);
1629
1630        # assert the validity - will croak if the config is invalid
1631        Crypt::HSXKPasswd->is_valid_config($config, croak => 1);
1632
1633    This function must be passed a hashref to test as the first argument.
1634    The function returns 1 if the passed config is valid, and 0 otherwise.
1635
1636    Optionally, a named argument `croak' can also be passed to control
1637    whether or not the function should croak if the config is invalid. The
1638    value of this named argument should be `1' or `0'.
1639
1640    When calling the function with `croak' set to `1', the message thrown by
1641    croak will explain why the config is invalid.
1642
1643        use English qw( -no_match_vars );
1644        eval{
1645            Crypt::HSXKPasswd->is_valid_config($config, croak => 1);
1646        }or do{
1647            print "ERROR - config is invalid because: $EVAL_ERROR\n";
1648        }
1649
1650    module_config()
1651        my $debug_val = Crypt::HSXKPasswd->module_config('DEBUG'); # getter
1652        Crypt::HSXKPasswd->module_config('DEBUG', 1); # setter
1653
1654    This function is used to access or alter the value of one of the module
1655    configuration settings. The first function must always be a valid module
1656    configuration key name. If no second argument is provided, the value
1657    stored in the module configuration key will not be updated. To update
1658    the stored value, pass a new value as a second argument. Regardless of
1659    whether or not a second argument is passed, the value stored in the
1660    module configuration key is always returned.
1661
1662    The function will croak if called with an invalid module configuration
1663    key name, or passed an invalid new value.
1664
1665    For a list of the module configuration keys, see the MODULE
1666    CONFIGURATION section of this document.
1667
1668    preset_config()
1669        my $config = Crypt::HSXKPasswd->preset_config('XKCD');
1670
1671    This function returns the config hashref for a given preset. See above
1672    for the list of available presets.
1673
1674    The first argument this function accepts is the name of the desired
1675    preset as a scalar. If an invalid name is passed, the function will
1676    carp. If no preset is passed the preset `DEFAULT' is assumed.
1677
1678    This function can optionally accept a second argument, a hashref
1679    containing keys with values to override the defaults with.
1680
1681        my $config = Crypt::HSXKPasswd->preset_config(
1682            'XKCD',
1683            {case_transform => 'INVERT'}
1684        );
1685
1686    When overrides are present, the function will carp if an invalid key or
1687    value is passed, and croak if the resulting merged config is invalid.
1688
1689    preset_definition()
1690        my %preset_def = Crypt::HSXKPasswd->preset_definition('XKCD');
1691
1692    This function returns a hash defining a preset. The hash contains an
1693    English description of the preset indexed be `description' and a config
1694    hashref indexed by `config'.
1695
1696    The function expects to be called with one argument, a valid preset
1697    name, but it can be called without arguments, in which case it will
1698    return the definition for the preset c<DEFAULT>.
1699
1700    You can see all the defined presets in the PRESETS section of this
1701    document, and you can get a list of valid preset names programatically
1702    with the function `defined_presets()'.
1703
1704    preset_definitions()
1705        my %preset_defs = Crypt::HSXKPasswd->preset_definitions();
1706
1707    This function returns a hash of all defined presets indexed by preset
1708    name. Each preset definition is a hash as returned by
1709    `preset_definition()'.
1710
1711    This function does not take any arguments.
1712
1713    presets_json()
1714        my $json_string = Crypt::HSXKPasswd->presets_json();
1715
1716    This function returns a JSON string representing all the defined
1717    configs, including their descriptions.
1718
1719    The returned JSON string represents a hashref indexed by three keys:
1720    `defined_keys' contains an array of preset identifiers, `presets'
1721    contains the preset configs indexed by reset identifier, and
1722    `preset_descriptions' contains a hashref of descriptions indexed by
1723    preset identifiers.
1724
1725    preset_description()
1726        my $description = Crypt::HSXKPasswd->preset_description('XKCD');
1727
1728    This function returns the description for a given preset. See above for
1729    the list of available presets.
1730
1731    The first argument this function accepts is the name of the desired
1732    preset as a scalar. If an invalid name is passed, the function will
1733    carp. If no preset is passed the preset `DEFAULT' is assumed.
1734
1735    presets_to_string()
1736        print Crypt::HSXKPasswd->presets_to_string();
1737
1738    This function returns a string containing a description of each defined
1739    preset and the configs associated with the presets.
1740
1741  COMMANDLINE INTERFACE
1742    The module ships with a commandline interface to this library, simply
1743    called `hsxkpasswd'.
1744
1745    This interface allows for the generation of multiple passwords at a
1746    time, the use of presets and preset overrides, the use of custom
1747    password generator configurations, the use of custom word sources, and
1748    the use of custom random number generators.
1749
1750    Both preset overrides and password generator configurations must be
1751    specified in JSON format.
1752
1753    Examples
1754    Generate a single password using all the default settings:
1755
1756        hsxkpasswd
1757
1758    Generate five passwords using the default settings:
1759
1760        hsxkpasswd 5
1761
1762    Generate five passwords using the `XKCD' preset:
1763
1764        hsxkpasswd -p XKCD 5
1765
1766    Generate five passwords using the `XKCD' preset with an overridden
1767    password generator configuration key:
1768
1769        hsxkpasswd -p XKCD -o '{"separator_character" : "*"}' 5
1770
1771    Generate five passwords using a custom password generator configuration
1772    stored in a text file in JSON format:
1773
1774        hsxkpasswd -c my_config.json
1775
1776    Further Reading
1777    The examples above are just a sample of what the command can do, for
1778    complete documentation, run the command with the -h flag:
1779
1780        hsxkpasswd -h
1781
1782    If you are new to JSON, you may find the following links useful:
1783
1784    *   JSON on Wikipedia - http://en.wikipedia.org/wiki/JSON
1785
1786    *   A free online JSON validator -
1787        http://jsonformatter.curiousconcept.com
1788
1789    *   A JSON tutorial from W3Schools - http://www.w3schools.com/json/
1790
1791  ENTROPY CHECKING
1792    For security reasons, this module's default behaviour is to warn (using
1793    `carp()') when ever the loaded combination of word source and
1794    configuration would result in low-entropy passwords. When the
1795    constructor is invoked, or when an instance's the word source or config
1796    are altered (using `dictionary()' or `config()'), the entropy is
1797    re-calculated and re-checked against the defined minima.
1798
1799    Entropy is calculated and checked for two scenarios. Firstly, for the
1800    best-case scenario, when an attacker has no prior knowledge about the
1801    password, and must resort to a brute-force attack. And secondly, for the
1802    worst-case scenario, when the attacker is assumed to know that this
1803    module was used to generate the password, and, that the attacker has a
1804    copy of the word source and config settings used to generate the
1805    password.
1806
1807    Entropy checking is controlled via three module configuration variables
1808    (which can be accessed and updated using the function
1809    `module_config()'):
1810
1811    *   `ENTROPY_MIN_BLIND' - the minimum acceptable entropy in bits for a
1812        brute-force attack. The default value is 78bits, the equivalent to a
1813        12 character password consisting of mixed-case letters, digits, and
1814        symbols.
1815
1816    *   `ENTROPY_MIN_SEEN' - the minimum acceptable entropy in bits for a
1817        worst-case scenario (where the word source and config are known).
1818        The default value is 52bits, equivalent to an 8 character password
1819        consisting of mixed-case letters, digits, and symbols.
1820
1821    *   `ENTROPY_WARNINGS' - this variable can be used to control the
1822        emission of entropy warnings. The following values are valid:
1823
1824        *   `ALL' - all entropy warnings are emitted. This is the default
1825            value.
1826
1827        *   `BLIND' - only warnings for the best-case scenario are emitted.
1828            I.e. warnings for the worst-case scenario (attacker has full
1829            knowledge) are suppressed.
1830
1831        *   `NONE' - all entropy warnings are suppressed.
1832
1833    Caveats
1834    The entropy calculations make some assumptions which may in some cases
1835    lead to the results being inaccurate. In general, an attempt has been
1836    made to always round down, meaning that in reality the entropy of the
1837    produced passwords may be higher than the values calculated by the
1838    package.
1839
1840    When calculating the entropy for brute force attacks on configurations
1841    that can result in variable length passwords, the shortest possible
1842    password is assumed.
1843
1844    When calculating the entropy for brute force attacks on configurations
1845    that contain at least one symbol, it is assumed that an attacker would
1846    have to brute-force-check 33 symbols. This is the same value used by
1847    Steve Gibson's *Password Haystacks* calculator
1848    (https://www.grc.com/haystack.htm).
1849
1850    When calculating the entropy for worst-case attacks on configurations
1851    that contain symbol substitutions where the replacement is more than 1
1852    character long the possible extra length is ignored.
1853
1854  WORD SOURCES (DICTIONARIES)
1855    The abstract class `Crypt::HSXKPasswd::Dictionary' acts as a base class
1856    for sources of words for use by this module. Word sources should extend
1857    this base class and implement the function `word_list()', which should
1858    return an array of words.
1859
1860    In order to produce secure passwords it's important to use a word source
1861    that contains a large selection of words with a good mix of different
1862    lengths of words.
1863
1864    The module ships with a number of pre-defined word sources:
1865
1866    `Crypt::HSXKPasswd::Dictionary::DE'
1867    A German word list based on the GPL-licensed German dictionary for
1868    WinEdit by Juergen Vierheilig.
1869
1870    Note: This module is licensed under the GPL, not the BSD license used
1871    for the majority of this project.
1872
1873    `Crypt::HSXKPasswd::Dictionary::EN'
1874    A default word list consisting of English words and place names.
1875
1876    `Crypt::HSXKPasswd::Dictionary::ES'
1877    A Spanish word list based on the BSD-licensed Spanish dictionary for
1878    WinEdit by Juan L. Varona from the Universidad de La Rioja.
1879
1880    `Crypt::HSXKPasswd::Dictionary::FR'
1881    A French word list based on the GPL-licensed French dictionary for
1882    WinEdit.
1883
1884    Note: This module is licensed under GPL V2, not the BSD license used for
1885    the majority of this project.
1886
1887    `Crypt::HSXKPasswd::Dictionary::IT'
1888    An Italian word list based on the free-for-non-commerical-use Italian
1889    dictionary for WinEdit by Karl Koeller.
1890
1891    Note: This module is licensed under GPL V2, not the BSD license used for
1892    the majority of this project.
1893
1894    `Crypt::HSXKPasswd::Dictionary::NL'
1895    A Dutch/Flemish word list based on the GPL-licensed Dutch dictionary for
1896    WinEdit.
1897
1898    Note: This module is licensed under GPL V2, not the BSD license used for
1899    the majority of this project.
1900
1901    `Crypt::HSXKPasswd::Dictionary::PT'
1902    A Portuguese word list based on the GPL-licensed Portuguese dictionary
1903    for WinEdit compiled by Bernhard Enders (building on work by Raimundo
1904    Santos Moura & Ricardo Ueda Karpischek).
1905
1906    Note: This module is licensed under GPL V2.1, not the BSD license used
1907    for the majority of this project.
1908
1909    `Crypt::HSXKPasswd::Dictionary::System'
1910    This class tries to find and use a Unix words file on the system.
1911
1912    The constructor croaks if no system words file can be found.
1913
1914    Usage
1915        my $word_source = Crypt::HSXKPasswd::Dictionary::System->new();
1916
1917    `Crypt::HSXKPasswd::Dictionary::Basic'
1918    This class can be initialised from a words file, or from an array ref
1919    containing words.
1920
1921    Usage
1922        my $word_source = Crypt::HSXKPasswd::Dictionary::Basic->new('file_path');
1923        my $word_source = Crypt::HSXKPasswd::Dictionary::Basic->new(
1924            'file_path',
1925            'Latin1'
1926        );
1927        my $word_source = Crypt::HSXKPasswd::Dictionary::Basic->new($array_ref);
1928
1929    The rules for the formatting of dictionary files are simple. Dictionary
1930    files must contain one word per line. Words shorter than four letters
1931    will be ignored, as will all lines starting with the # symbol. Files are
1932    assumed to be UTF-8 encoded, but an optional second argument can be
1933    passed specifying a different file encoding.
1934
1935    This format is the same as that of the standard Unix Words file, usually
1936    found at `/usr/share/dict/words' on Unix and Linux operating systems
1937    (including OS X).
1938
1939  RANDOM NUMBER SOURCES
1940    In order to minimise the number of non-standard modules this module
1941    requires, the default source of randomness is Perl's built-in `rand()'
1942    function. This provides a reasonable level of randomness, and should
1943    suffice for most users, however, some users will prefer to make use of
1944    one of the many advanced randomisation modules in CPAN, or, reach out to
1945    a web service like http://random.org for their random numbers. To
1946    facilitate both of these options, this module uses a cache of
1947    randomness, and provides an abstract Random Number Generator (RNG) class
1948    that can be extended.
1949
1950    The module can use an instance of any class that extends
1951    `Crypt::HSXKPasswd::RNG' as it's source of randomness. Custom RNG
1952    classes must implement the method `random_numbers()' which will be
1953    invoked on an instance of the class and passed one argument, the number
1954    of random numbers required to generate a single password. The function
1955    must return an array of random numbers between 0 and 1. The number of
1956    random numbers returned is entirely up to the module to decide. The
1957    number required for a single password is passed purely as a guide. The
1958    function must always return at least one random number.
1959
1960    The module ships with five standard RNGs (described below).
1961
1962    By default, the module will try to use one of the following four RNGs,
1963    listed from most to least preferred, depending on what is available on
1964    the system:
1965
1966    1   `Crypt::HSXKPasswd::RNG::Math_Random_Secure' (only available if
1967        `Math::Random::Secure' is installed on the system).
1968
1969    2   `Crypt::HSXKPasswd::RNG::Data_Entropy' (only available if
1970        `Data::Entropy::Algorithms' is installed on the system).
1971
1972    3   `Crypt::HSXKPasswd::RNG::DevUrandom' (only available on Linux/Unix
1973        systems with a `/dev/urandom').
1974
1975    4   `Crypt::HSXKPasswd::RNG::Basic' (available on all systems because it
1976        uses Perl's built-in `rand()' function).
1977
1978    If the constructor is called without specifying an RNG, and if the only
1979    available RNG is `Crypt::HSXKPasswd::RNG::Basic', a warning will be
1980    thrown suggesting installing `Math::Random::Secure' or
1981    `Data::Entropy::Algorithms'.
1982
1983    The module also ships with a fifth RNG,
1984    `Crypt::HSXKPasswd::RNG::RandomDotOrg', but this one must be explicitly
1985    used, the constructor will never used it by default. As its name
1986    suggests, this class uses http://Random.Org/'s HTTP API to generate
1987    random numbers.
1988
1989    To explicitly use any particular RNG, create an instance of it, and
1990    either pass that instance to the constructor with the named argument
1991    `rng', or, set the RNG after instantiating the object using the `rng()'
1992    function.
1993
1994    Crypt::HSXKPasswd::RNG::Math_Random_Secure
1995        my $rng = Crypt::HSXKPasswd::RNG::Math_Random_Secure->new();
1996
1997    This is the preferred RNG because it is both fast and secure, but, it
1998    requires the non-standard module `Math::Random::Secure'
1999    (http://search.cpan.org/perldoc?Math%3A%3ARandom%3A%3ASecure) be
2000    installed.
2001
2002    Crypt::HSXKPasswd::RNG::Data_Entropy
2003        my $rng = Crypt::HSXKPasswd::RNG::Data_Entropy->new();
2004
2005    This RNG is secure, but it is quite slow (about six times slower than
2006    `Crypt::HSXKPasswd::RNG::Math_Random_Secure'), and it requires the
2007    non-standard module `Data::Entropy::Algorithms'
2008    (http://search.cpan.org/perldoc?Data%3A%3AEntropy%3A%3AAlgorithms) be
2009    installed.
2010
2011    Crypt::HSXKPasswd::RNG::DevUrandom
2012        my $rng = Crypt::HSXKPasswd::RNG::DevUrandom->new();
2013
2014    This RNG is secure and relatively fast (faster than
2015    `Crypt::HSXKPasswd::RNG::Data_Entropy' but slower than
2016    `Crypt::HSXKPasswd::RNG::Math_Random_Secure'), but is only available on
2017    Linux/Unix systems with a `/dev/urandom' special file.
2018
2019    Crypt::HSXKPasswd::RNG::Basic
2020        my $rng = Crypt::HSXKPasswd::RNG::Basic->new();
2021
2022    This RNG uses Perl's built-in `rand()' function as its source of
2023    randomness, and this is sub-optimal. The Perl docs warn that `rand()' is
2024    not a particularly good source of random numbers, and advises against
2025    its use for cryptography.
2026
2027    This RNG provides a base-line, and should only be used if none of the
2028    better RNGs are available. While it is sub-optimal, it will still
2029    generate passwords with sufficient entropy in most situations.
2030    Ultimately, even using this imperfect RNG, this module will still
2031    produce passwords that are much better than those produced by the human
2032    imagination!
2033
2034    Crypt::HSXKPasswd::RNG::RandomDotOrg
2035        my $rng = Crypt::HSXKPasswd::RNG::RandomDotOrg->new('my.address@my.dom');
2036        my $rng = Crypt::HSXKPasswd::RNG::RandomDotOrg->new('my.address@my.dom',
2037            timeout => 180,
2038            num_passwords => 3,
2039        );
2040
2041    This RNG serves as a usable example of an RNG that queries a web
2042    service. As its name suggests, this class uses http://Random.Org/'s HTTP
2043    API to generate random numbers.
2044
2045    In order to comply with Random.Org's client guidelines
2046    (https://www.random.org/clients/), this module requires that a valid
2047    email address be passed as the first argument.
2048
2049    The client guidelines also request that clients use long timeouts, and
2050    batch their requests. They prefer to be asked for more number less
2051    frequently than less numbers more frequently. For this reason the
2052    class's default behaviour is to use a timeout of 180 seconds, and to
2053    request enough random numbers to generate three passwords at a time.
2054
2055    These defaults can be overridden by passing named arguments to the
2056    constructor after the email address. The following named arguments are
2057    supported:
2058
2059    *   `timeout' - the timeout to use when making HTTP requests to
2060        Random.Org in seconds (the default is 180).
2061
2062    *   `num_passwords' - the number of password generations to fetch random
2063        numbers for per request from Random.org. This value is in effect a
2064        multiplier for the value passed to the `random_numbers()' function
2065        by `Crypt::HSXKPasswd'.
2066
2067        `num_absolute' - the absolute number of random numbers to fetch per
2068        request to Random.Org. This argument takes precedence over
2069        `num_passwords'.
2070
2071    `num_passwords' and `num_absolute' should not be used together, but if
2072    they are, `num_absolute' use used, and `num_passwords' is ignored.
2073
2074    This class requires a number of modules not used by any other classes
2075    under `Crypt::HSXKPasswd', and not listed in that module's requirements.
2076    If all of the following modules are not installed, the constructor will
2077    croak:
2078
2079    *   `Email::Valid'
2080
2081    *   `LWP::UserAgent'
2082
2083    *   `Mozilla::CA'
2084
2085    *   `URI'
2086
2087DIAGNOSTICS
2088    By default this module does all of it's error notification via the
2089    functions `carp()', `croak()', and `confess()' from the `Carp' module.
2090    Optionally, all error messages can also be printed to a stream. To
2091    enable the printing of messages, set the `LOG_ERRORS' module
2092    configuration variable to `1'. All error messages will then be printed
2093    to the stream defined by the module configuration variable `LOG_STREAM',
2094    which is set to `STDERR' by default.
2095
2096    Ordinarily this module produces very little output. To enable more
2097    verbose output the module configuration variable `DEBUG' can be set to
2098    `1'. Debug message are printed to the stream specified by the module
2099    variable `LOG_STREAM'.
2100
2101    This module produces output at three severity levels:
2102
2103    *   `DEBUG' - this output is completely suppressed unless the module
2104        configuration variable `DEBUG' is set to `1'. All debug messages are
2105        printed to the stream defined in the module configuration variable
2106        `LOG_STREAM' (regardless of the the value of the module
2107        configuration variable `LOG_ERRORS').
2108
2109    *   `WARNING' - warning messages are always thrown with `carp()', and
2110        also printed to the stream specified by the module configuration
2111        variable `LOG_STREAM' if the module configuration variable
2112        `LOG_ERRORS' is set to `1'.
2113
2114    *   `ERROR' - error messages are usually thrown with `croak()', but will
2115        be thrown with `confess()' if the module configuration variable
2116        `DEBUG' is set to `1'. If the module configuration variable
2117        `LOG_ERRORS' is set to `1' errors are also printed to the stream
2118        defined by the module configuration variable `LOG_STREAM', including
2119        a stack trace if the module configuration variable `DEBUG' is set to
2120        `1' and the module `Devel::StackTrace' is installed.
2121
2122    The value stored in a module configuration variable can be accessed and
2123    updated using the function `module_config()'.
2124
2125CONFIGURATION AND ENVIRONMENT
2126    This module does not currently support configuration files, nor does it
2127    currently interact with the environment. It may do so in future
2128    versions.
2129
2130DEPENDENCIES
2131    This module requires the following Perl modules:
2132
2133    *   `Carp' - http://search.cpan.org/perldoc?Carp
2134
2135    *   `Clone' - http://search.cpan.org/perldoc?Clone
2136
2137    *   `DateTime' - http://search.cpan.org/perldoc?DateTime
2138
2139    *   `English' - http://search.cpan.org/perldoc?English
2140
2141    *   `Fatal' - http://search.cpan.org/perldoc?Fatal
2142
2143    *   `File::HomeDir' - http://search.cpan.org/perldoc?File%3A%3AHomeDir
2144
2145    *   `Getopt::Long' - http://search.cpan.org/perldoc?Getopt%3A%3ALong
2146
2147    *   `JSON' - http://search.cpan.org/perldoc?JSON
2148
2149    *   `List::MoreUtils' -
2150        http://search.cpan.org/perldoc?List%3A%3AMoreUtils
2151
2152    *   `Math::BigInt' - http://search.cpan.org/perldoc?Math%3A%3ABigInt
2153
2154    *   `Math::Round' - http://search.cpan.org/perldoc?Math%3A%3ARound
2155
2156    *   `Module::Load' - http://search.cpan.org/perldoc?Module%3A%3ALoad
2157
2158    *   `Pod::Usage' - http://search.cpan.org/perldoc?Pod%3A%3AUsage
2159
2160    *   `Readonly' - http://search.cpan.org/perldoc?Readonly
2161
2162    *   `Scalar::Util' - http://search.cpan.org/perldoc?Scalar%3A%3AUtil
2163
2164    *   `strict' - http://search.cpan.org/perldoc?strict
2165
2166    *   `Text::Unidecode' -
2167        http://search.cpan.org/perldoc?Text%3A%3AUnidecode
2168
2169    *   `Type::Library' - http://search.cpan.org/perldoc?Type%3A%3ALibrary
2170
2171    *   `Type::Params' - http://search.cpan.org/perldoc?Type%3A%3AParams
2172
2173    *   `Type::Tiny' - http://search.cpan.org/perldoc?Type%3A%3ATiny
2174
2175    *   `Types::Standard' -
2176        http://search.cpan.org/perldoc?Types%3A%3AStandard
2177
2178    *   `warnings' - http://search.cpan.org/perldoc?warnings
2179
2180    The module can also optionally use the following Perl modules:
2181
2182    *   `Data::Entropy::Algorithms' -
2183        http://search.cpan.org/perldoc?Data%3A%3AEntropy%3A%3AAlgorithms
2184
2185        Used by the RNG class `Crypt::HSXKPasswd::RNG::Data_Entropy'.
2186
2187    *   `Devel::StackTrace' -
2188        http://search.cpan.org/perldoc?Devel%3A%3AStackTrace
2189
2190        Used for printing stack traces with error messages if
2191        `$XKPasswd::DEBUG' and `$XKPasswd::LOG_ERRORS' both evaluate to
2192        true. If the module is not installed the stack traces will be
2193        omitted from the log messages.
2194
2195    *   `Email::Valid' - http://search.cpan.org/perldoc?Email%3A%3AValid
2196
2197        Used by the Random.Org RNG class
2198        `Crypt::HSXKPasswd::RNG::RandomDotOrg'.
2199
2200    *   `LWP::UserAgent' - http://search.cpan.org/perldoc?LWP%3A%3AUserAgent
2201
2202        Used by the Random.Org RNG class
2203        `Crypt::HSXKPasswd::RNG::RandomDotOrg'.
2204
2205    *   `Math::Random::Secure' -
2206        http://search.cpan.org/perldoc?Math%3A%3ARandom%3A%3ASecure
2207
2208        Used by the RNG class `Crypt::HSXKPasswd::RNG::Math_Random_Secure'.
2209
2210    *   `Mozilla::CA' - http://search.cpan.org/perldoc?Mozilla%3A%3ACA
2211
2212        Indirectly required by the Random.Org RNG class
2213        `Crypt::HSXKPasswd::RNG::RandomDotOrg' because without it
2214        `LWP::UserAgent' can't use HTTPS, and the Random.Org API uses HTTPS.
2215
2216    *   `URI' - http://search.cpan.org/perldoc?URI
2217
2218        Used by the Random.Org RNG class
2219        `Crypt::HSXKPasswd::RNG::RandomDotOrg'.
2220
2221INCOMPATIBILITIES
2222    This module has no known incompatibilities.
2223
2224BUGS AND LIMITATIONS
2225    There are no known bugs in this module.
2226
2227    Please report any bugs you may find on the module's GitHub page:
2228    https://github.com/bbusschots/xkpasswd.pm.
2229
2230LICENCE AND COPYRIGHT
2231    Copyright (c) 2014-15, Bart Busschots T/A Bartificer Web Solutions All
2232    rights reserved.
2233
2234    Redistribution and use in source and binary forms, with or without
2235    modification, are permitted provided that the following conditions are
2236    met:
2237
2238    1.  Redistributions of source code must retain the above copyright
2239        notice, this list of conditions and the following disclaimer.
2240
2241    2.  Redistributions in binary form must reproduce the above copyright
2242        notice, this list of conditions and the following disclaimer in the
2243        documentation and/or other materials provided with the distribution.
2244
2245    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2246    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2247    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
2248    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
2249    OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2250    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2251    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2252    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2253    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2254    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2255    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2256
2257    The following components of this package are covered by the more
2258    restrictive GPL V2 license https://www.gnu.org/licenses/gpl-2.0.html:
2259
2260    *   The `share/sample_dict_DE.txt' text file.
2261
2262    *   The `Crypt::HSXKPasswd::Dictionary::DE' Perl module.
2263
2264    *   The `share/sample_dict_FR.txt' text file.
2265
2266    *   The `Crypt::HSXKPasswd::Dictionary::FR' Perl module.
2267
2268    *   The `share/sample_dict_IT.txt' text file.
2269
2270    *   The `Crypt::HSXKPasswd::Dictionary::IT' Perl module.
2271
2272    *   The `share/sample_dict_NL.txt' text file.
2273
2274    *   The `Crypt::HSXKPasswd::Dictionary::NL' Perl module.
2275
2276    *   The `share/sample_dict_PT.txt' text file.
2277
2278    *   The `Crypt::HSXKPasswd::Dictionary::PT' Perl module.
2279
2280AUTHOR
2281    Bart Busschots (mailto:bart@bartificer.net)
2282
2283