Crypt::RandPasswd(3)

πŸ“¦
version 0.07 Β· 4 versions
, in epel 9

πŸ’– NAME πŸ’–

Hey bestie, meet Crypt::RandPasswd(3) β€” the random password generator based on FIPS-181, hanging out in User Contributed Perl Documentation. That's the whole vibe. πŸ’…

✨ SYNOPSIS ✨

Okay so here's how you call it, and yes you can override the defaults for these functions:

use Crypt::RandPasswd;
( $word, $hyphenated ) = Crypt::RandPasswd->word( $minlen, $maxlen );
$word = Crypt::RandPasswd->word( $minlen, $maxlen );
$word = Crypt::RandPasswd->letters( $minlen, $maxlen );
$word = Crypt::RandPasswd->chars( $minlen, $maxlen );

# override the defaults for these functions:
*Crypt::RandPasswd::rng = \&my_random_number_generator;
*Crypt::RandPasswd::restrict = \&my_restriction_filter;

🌸 DESCRIPTION 🌸

Crypt::RandPasswd provides three functions that can be used to generate random passwords, constructed from words, letters, or characters. Three little functions, three whole flavors of password generation.

This code is a Perl implementation of the Automated Password Generator standard, like the program described in "A Random Word Generator For Pronounceable Passwords" (not available on-line). This code is a re-engineering of the program contained in Appendix A of FIPS Publication 181, "Standard for Automated Password Generator". In accordance with the standard, the results obtained from this program are logically equivalent to those produced by the standard. That last bit is a flex, ngl.

😭 CAVEATS 😭

πŸ› Bugs πŸ›

The function to generate a password can sometimes take an extremely long time. Like, not a cute little pause β€” an extremely long time. Go hydrate. πŸ’€

🚨 Deviations From Standard 🚨

This implementation deviates in one critical way from the standard upon which it is based: the random number generator in this implementation does not use DES. Instead, it uses perl's built-in rand() function, which in turn is (usually) built on the pseudo-random number generator functions of the underlying C library.

However, the random function can be replaced by the user if desired. (See rng.) Customizable? Obsessed.

🧚 Functions 🧚

Okay bestie, here come the functions one by one. Keep up. 🫢

πŸ¦‹ word πŸ¦‹

word = word( minlen, maxlen );
( word, hyphenated_form ) = word( minlen, maxlen );

Generates a random word, as well as its hyphenated form. The length of the returned word will be between minlen and maxlen. Two-for-one word moment.

πŸ¦‹ letters πŸ¦‹

word = letters( minlen, maxlen );

Generates a string of random letters. The length of the returned word is between minlen and maxlen. Calls random_chars_in_range( 'a' => 'z' ).

πŸ¦‹ chars πŸ¦‹

word = chars( minlen, maxlen );

Generates a string of random printable characters. The length of the returned word is between minlen and maxlen. Calls random_chars_in_range( '!' => '~' ).

πŸ¦‹ random_chars_in_range πŸ¦‹

word = random_chars_in_range( minlen, maxlen, lo_char => hi_char );

Generates a string of printable characters. The length of the returned string is between minlen and maxlen. Each character is selected from the range of ASCII characters delimited by (lo_char,hi_char). Range filter realness.

πŸ¦‹ rand_int_in_range πŸ¦‹

n = rand_int_in_range( min, max );

Returns an integer between min and max, inclusive. Calls rng like so:

n = min + int( rng( max - min + 1 ) )

πŸ¦‹ random_element πŸ¦‹

e = random_element( \@elts )

Selects a random element from an array, which is passed by ref.

πŸ¦‹ rng πŸ¦‹

r = rng( n );

rng is designed to have the same interface as the built-in rand function. The default implementation here is a simple wrapper around rand, which is typically a wrapper for some pseudo-random number function in the underlying C library.

The reason for having this simple wrapper is so the user can easily substitute a different random number generator if desired. Since many rng's have the same interface as rand, replacing rng() is as simple as

{
    local $^W; # squelch sub redef warning.
    *Crypt::RandPasswd::rng = \&my_rng;
}

See rand. Plug-and-play rng, we love to see it.

πŸ¦‹ restrict πŸ¦‹

word = restrict( word );

A filter. Returns the arg unchanged if it is allowable; returns undef if not.

The default version of restrict() allows everything. You may install a different form to implement other restrictions, by doing something like this:

{
  local $^W; # squelch sub redef warning.
  *Crypt::RandPasswd::restrict = \&my_filter;
}

πŸ¦‹ init πŸ¦‹

This initializes the environment, which by default simply seeds the random number generator. Seeding era.

πŸ¦‹ get_syllable πŸ¦‹

Generate next unit to password, making sure that it follows these rules:

  1. Each syllable must contain exactly 1 or 2 consecutive vowels, where y is considered a vowel.
  2. Syllable end is determined as follows:

a. Vowel is generated and previous unit is a consonant and syllable already has a vowel. In this case, new syllable is started and already contains a vowel. b. A pair determined to be a "break" pair is encountered. In this case new syllable is started with second unit of this pair. c. End of password is encountered. d. "begin" pair is encountered legally. New syllable is started with this pair. e. "end" pair is legally encountered. New syllable has nothing yet.

  1. Try generating another unit if:

a. third consecutive vowel and not y. b. "break" pair generated but no vowel yet in current or previous 2 units are "not_end". c. "begin" pair generated but no vowel in syllable preceding begin pair, or both previous 2 pairs are designated "not_end". d. "end" pair generated but no vowel in current syllable or in "end" pair. e. "not_begin" pair generated but new syllable must begin (because previous syllable ended as defined in 2 above). f. vowel is generated and 2a is satisfied, but no syllable break is possible in previous 3 pairs. g. Second and third units of syllable must begin, and first unit is "alternate_vowel".

🌈 SEE ALSO 🌈

🏰 REPOSITORY 🏰

The repo is right here: https://github.com/neilbowers/Crypt-RandPasswd go star it bestie

πŸ‘‘ AUTHOR πŸ‘‘

JDPORTER@cpan.org (John Porter)

Now maintained by Neil Bowers neilb@cpan.org. Maintainer handoff, slay.

This perl module is free software; it may be redistributed and/or modified under the same terms as Perl itself.

That's the tea, bestie! πŸ’… This page is from perl v5.32.1, dated 2022-05-30, and yes β€” Crypt::RandPasswd(3). Mwah! 🫢

πŸ“¦ where this page comes from