Crypt:...assword(3pm)
π Crypt::GeneratePassword β the manual, but make it cute π
okay bestie, you know that card Crypt:...assword(3pm) in your man pages? That's this one. It's Crypt::GeneratePassword, and its whole job is generating secure random pronounceable passwords. Yes, both. We contain multitudes. π
β¨ NAME β¨
Crypt::GeneratePassword β generate secure random pronounceable passwords π¦
πΈ SYNOPSIS πΈ
use Crypt::GeneratePassword qw(word chars);
$word = word($minlen,$maxlen);
$word = chars($minlen,$maxlen);
*Crypt::GeneratePassword::restrict = \&my_restriction_filter;
*Crypt::GeneratePassword::random_number = \&my_random_number_generator;
look at that. four lines. iconic. π
π DESCRIPTION π
Crypt::GeneratePassword generates random passwords that are (more or less) pronounceable. ngl that "more or less" is doing a lot of work but we move. β¨
Unlike Crypt::RandPasswd, it does not use the FIPS-181 NIST standard, which is proven to be insecure π. It does use a similar interface though, so it should be a drop-in replacement in most cases. slay for backwards compatibility fr fr.
If you want passwords from a language that isn't English, you can use one of the packaged alternate unit tables or generate your own. details below, keep scrolling bestie π
For details on why FIPS-181 is insecure and why the solution used in this module is reasonably secure, see "A New Attack on Random Pronounceable Password Generators" by Ravi Ganesan</> and Chris Davies</> β it's available online in may places, so use your favourite search engine. π (yes, the page really says "may places". we don't fix lore here, we respect it. π)
This module improves on FIPS-181 using a true random selection with the word generator as mere filter. other glow-ups include:
- better pronounceability using third order approximation instead of second order π
- multi-language support π
The drawback of this method is that it is usually slower. Then again... computer speed has improved a little since 1977. ππ
π Functions π
π chars
$word = chars($minlen, $maxlen [, $set [, $characters, $maxcount ] ... ] );
Generates a completely random word between $minlen and $maxlen in length. If $set is given, it must be an array ref of characters to use. You can restrict occurrence of some characters by providing ($characters, $maxcount) pairs β as many as you like, girl, go off. $characters must be a string consisting of those characters which may appear at most $maxcount times in the word.
Note that the length is determined via relative probability, not uniformly. so don't come for her about the distribution, she told you upfront. π
π§ word
$word = word($minlen, $maxlen [, $lang [, $numbers [, $caps [, $minfreq, $avgfreq ] ] ] );
$word = word3($minlen, $maxlen [, $lang [, $numbers [, $caps [, $minfreq, $avgfreq ] ] ] );
Generates a random pronounceable word. The length of the returned word will be between $minlen and $maxlen. β¨
- If you supply a non-zero value for
$numbers, up to that many numbers and special characters will occur in the password. π’ - If you specify a non-zero value for
$caps, up to this many characters will be upper case. π $langis the language description to use, loaded viaload_languageor built-in. Built-in languages are:'en'(english) and'de'(german). Contributions welcome. π The default language is'en'but may be changed by callingload_languagewith a true value as third parameter. Passundefas language to select the current default language.$minfreqand$minsumdetermine quality of the password:$minfreqand$avgfreqare the minimum frequency each quad/trigram must have and the average frequency that the quad/trigrams must have for a word to be selected. Both are values between0.0and1.0, specifying the percentage of the maximum frequency.
Higher values create less secure, better pronounceable passwords and are slower. Useful $minfreq values are usually between 0.001 and 0.0001, useful $avgfreq values are around 0.05 for trigrams (word3) and 0.001 for quadgrams (word). pick your fighter π₯
π₯ analyze
$ratio = analyze($count,@word_params);
$ratio = analyze3($count,@word_params);
Returns a statistical(!)</> security ratio to measure password quality. $ratio is the ratio of passwords chosen among all possible ones, e.g. a ratio of 0.0149 means 1.49% of the theoretical password space was actually considered a pronounceable password.
Since this analysis is only statistical, it proves absolutely nothing if you are deeply concerned about security β but in that case you should use chars(), not word(), anyways. π In reality, it says a lot about your chosen parameters if you use large values for $count.
π generate_language
$language_description = generate_language($wordlist);
Generates a language description which can be saved in a file and/or loaded with load_language. $wordlist can be:
- a string containing whitespace separated words
- an array ref containing one word per element
- a file handle or name to read words from, one word per line7
Alternatively, you may pass an array directly, not as reference. A language description is about 1MB in size. yep. one whole megabyte of vibes. π«Ά
If you generate a general-purpose language description for a language not yet built-in, feel free to contribute it for inclusion into this package. we love a community moment. πΈ
π¦ load_language
load_language($language_description, $name [, $default]);
Loads a language description which is then available in words(). $language_description is a string returned by generate_language, $name is a name of your choice which is used to select this language as the fifth parameter of words(). You should use the well-known ISO two letter language codes if possible, for best interoperability. π
If you specify $default with a true value, this language will be made global default language. If you give undef as $language_description, only the default language will be changed.
π random_number
$number = random_number($limit);
Returns a random integer between 0 (inclusive) and $limit (exclusive). Change this to a function of your choice by doing something like this:
sub my_rng ($) {
...
}
{
# suppress warning about function being redefined
no warnings 'redefine';
*Crypt::GeneratePassword::random_number = \&my_rng;
}
The default implementation uses perl's rand(), which might not be appropriate for some sites. so if your site has Opinionsβ’, this is your moment bestie. π
π restrict
$forbidden = restrict($word,$language);
Filters undesirable words. Returns false if the $word is allowed in language $lang, false otherwise. Change this to a function of your choice by doing something like this:
sub my_filter ($$) {
...
}
{
no warnings 'redefine';
*Crypt::GeneratePassword::restrict = \&my_filter;
}
The default implementation scans for a few letter sequences that english or german people might find offending, mostly because of their sexual nature π. You might want to hook up a regular password checker here, or a wordlist comparison. honestly a great idea, do it.
π SEE ALSO π
Crypt::RandPasswd
π REPOSITORY π
<https://github.com/neilb/Crypt-GeneratePassword>
β¨ AUTHOR β¨
Copyright 2002 by JΓΆrg Walter</> <jwalt@cpan.org>, inspired by ideas from Tom Van Vleck</> and Morris Gasser/FIPS-181</>.
Now maintained by Neil Bowers</> <neilb@cpan.org> π«Ά
π COPYRIGHT π
This perl module is free software; it may be redistributed and/or modified under the same terms as Perl itself.
and that's the whole thing, bestie π¦ no cap. this page is perl v5.36.0, dated 2022-10-13, and it literally shipped as Crypt:...assword(3pm) β the name got truncated in the header and honestly? she's not fixing it. periodt. π
β¨
π¦ where this page comes from
- ubuntu noble: libcrypt-generatepassword-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcrypt-generatepassword-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcrypt-generatepassword-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms