20 releases (13 breaking)

0.14.1 Apr 4, 2024
0.14.0 Dec 11, 2023
0.13.0 Dec 1, 2023
0.12.0 Nov 29, 2023
0.2.0 Sep 9, 2019

#205 in Command line utilities

MIT license

130KB
907 lines

About

xkcd-style password generator

xkcd #936: Password Strength

Usage

$ xpg -h
xpg 0.14.1 <https://crates.io/crates/xpg>

xkcd-style password generator

Usage: xpg [OPTIONS] [PATTERNS]...

Arguments:
  [PATTERNS]...  Pattern(s) (see note 1) [default: `wwww`, `-L`: `{a}`]

Options:
  -c, --count <NUMBER>     Number of passwords (0:∞ ) [default: 1]
  -l, --length <NUMBER>    Length
  -m, --minimum <NUMBER>   Minimum length
  -M, --maximum <NUMBER>   Maximum length
  -a, --attempts <NUMBER>  Attempts (see note 2) [default: 10]
  -C, --config <PATH>      Configuration file
  -e, --extended           Merge extended words (see note 3)
  -L, --list               List words in `{sub}`(s)
  -d, --dump-config        Print configuration
  -r, --readme             Print readme
  -h, --help               Print help
  -V, --version            Print version

---

Notes

1. Patterns
    * Words
        * `W`: WORD
        * `w`: word
        * `T`: Word
        * `k`: `shuffle(cccc(c|d)(C|c))`
        * `{sub}`: see `WordKind`s section in readme
    * Characters
        * `C`: A-Z
        * `c`: a-z
        * `d`: 0-9
        * `s`: `~!@#$%^&*-_=+;:,./?()[]{}<>`
        * `a`: `C` | `c` | `d` | `s`
    * Special
        * `keychain`
        * `codename`
        * `codename-series`
        * `haiku`
        * `haiku+`
        * `haiku-`
        * `haiku--`
        * `haiku++`
        * `haiku+++`

2. Ten attempts are made to satisfy the given length requirements by default;
   use `-a N` and set `N` to the number of attempts to increase chances.
   It will exit with an error if unable to satisfy requirements; some
   configurations will always produce an error.

3. Extended words are only available in exclusively extended word kinds by
   default; however, with `-e`, they are merged with regular word kinds; use
   with the `-L` option to see its effect.
$ xpg -V
xpg 0.14.1

See also the Configuration section below.

Examples

$ xpg
judgegavemontanadraw

Generate 10 passwords

$ xpg -c 10
beginmoonmothertube
belgiuminsteadthingouter
windowideapoundsdoes
untilneedleneckabove
measurelikeriseamerica
doctorpropertyreacheduncle
donefoundprobableplease
newswednesdaybasketbroken
matterdevelopedincludepounds
provefrontlittlejordan

Generate passwords forever

or until Ctrl+C / SIGINT

$ xpg -c 0
moresincesoiltexas
finallyitselfevenmeat
crossteamdelawareridden
processthousandplaintone
bellnetherlandsedgebranches
suddenelsewingsstory
sundaywedgenatureaustria
sentsoldiersbeganwent
continuedspecialduskbecome
newskilledsomeonefarmers
^C

Generate a password with 8 words

$ xpg wwwwwwww
fingerbecamecitydemandlaughedmoscoweffectafraid

Generate 10 passwords with 8 words

$ xpg wwwwwwww -c 10
englishmondayamountwhatopinionislandthickdictionary
successenoughfullbusyearthinsectshellofrom
rolledpulledbelieveknownreasonchairshownloss
spreadwheatturnbrokeproductssouthbonescolor
governmentslowlysmallbridgeyellowwellwithinscore
likelytwelvepresentgirlinsteadmorningbookclock
bottleunderstoodoncefebruaryclosetookrulebetween
listlengthsilverduskscalefuturestaytoday
shownspainkissappeartheybritishpossibledied
whosemembersproudpropertystillgoessouthernlondon

Generate a password with 2 words followed by 3 digits

$ xpg wwddd
towardcare285

Generate a password with 2 words followed by 2 symbols

$ xpg wwss
showbrought&?

Generate a password with 2 words followed by a digit and a symbol

$ xpg wwds
warsawreal8-

Generate a password with 4 words followed by 2 lowercase letters

$ xpg wwwwcc
coastbloodfencehusbandzq

Generate a password with 4 words followed by 2 uppercase letters

$ xpg wwwwCC
untiljamaicasureshoutXU

Generate a password with 4 title case words

$ xpg TTTT
MilePromiseTeamRepresent

Generate a password with 4 uppercase words

$ xpg WWWW
HANGTHEMSELVESSHOWFOOT

Generate a password with 4 words followed by 5 any characters

An "any" character can be a lowercase letter, uppercase letter, digit, or symbol.

$ xpg wwwwaaaaa
noticebrightjumpedlandM44OE

Generate a password with 3 words and at least 15 characters

$ xpg www -m 15
signbellpartial

Generate a password with 3 words and no more than 20 characters

$ xpg www -M 20
divideprocessglass

Generate a password with 4 words and between 20 and 25 characters

$ xpg www -m 20 -M 25 -a 1000
patternmainstatement

See also Usage note 2.

Generate a password with 2 words, 3 digits, 1 symbol, and exactly 16 characters

$ xpg wwddds -l 16 -a 1000
monthsmadrid593+

See also Usage note 2.

Generate a password with a 1, 2 title case words, and !

$ xpg '1TT!'
1LossUpon!

Generate a password with 1 symbol, 2 adjectives, 1 noun, and 2 digits

$ xpg 's{adj}{adj}{n}dd'
!bettersoutherncompound00

Generate a password with 2 words and 1 extended word

$ xpg 'ww{ext}'
oxygenwalknorthdakota

Generate a password with 2 words and 1 title case extended word

$ xpg 'ww{T:ext}'
rememberrestMegaclite

Generate a password with 2 words and 1 uppercase extended word

$ xpg 'ww{W:ext}'
belfastfirmCOLORADO

Generate 10 passwords with 4 title case words and extended words merged

$ xpg -ec 10 TTTT
KilledHouseManySettle
FirmHuntConsiderMinute
MaterialLadderNearFruit
PickMayorEuantheTraining
PlanKalykeDemandHowever
MeanSendFineHold
HeavenDoesIronDemand
ProductsNatureVillageEarly
MayEffectNounToday
GoesDegreeDelawareParty

Generate a keychain-style password

$ xpg keychain
mwprb5-vCcmys-ynwmjo

Generate a code name

$ xpg codename
HIGH FRIENDS

Generate a code name series

$ xpg codename-series
FOURSTREAM BRITISHELEMENTS
FOURSTREAM SAMEWITHOUT
FOURSTREAM RICHSURPRISE
FOURSTREAM EQUALRADIO
FOURSTREAM ANGRYADVANCE
FOURSTREAM ELSETILL
FOURSTREAM LATERLIGHT
FOURSTREAM AFRAIDSTORE
FOURSTREAM PARTIALOBJECT
FOURSTREAM FLATOPINION

Generate a code name series with 20 code names

$ xpg codename-series -c 20
NEAREGGS CORRECTMONDAY
NEAREGGS SUDDENINTEREST
NEAREGGS OUTSIDESILVER
NEAREGGS SIMILARBUILD
NEAREGGS PLANEREACH
NEAREGGS THICKFIFTEEN
NEAREGGS THISTYPE
NEAREGGS MINUTERETURN
NEAREGGS THESEVIEW
NEAREGGS TALLCHARGE
NEAREGGS WESTSATURDAY
NEAREGGS MAINFEAR
NEAREGGS TWENTYGREEN
NEAREGGS ANIMALMOTHER
NEAREGGS THIRTEENCARE
NEAREGGS WIDEFREE
NEAREGGS ALONESOUND
NEAREGGS CONSONANTSINGLE
NEAREGGS NICEAUGUST
NEAREGGS REALHEAT

Generate a haiku

$ xpg haiku
Died experiment / Poor considerable stay / Copenhagen best

Generate a haiku with syllable pattern

$ xpg haiku+
Europe today fruit (2,2,1) / Considerable kept wire (5,1,1) / Cold suggested sight (1,3,1)

Generate a condensed haiku with syllable pattern

$ xpg haiku-
Developed-either(3,2)/However-inches-above(3,2,2)/Cotton-solution(2,3)

Generate a condensed haiku

$ xpg haiku--
Considerable/Take-electricity-thank/Season-nature-land

Generate a haiku with newlines

$ xpg haiku++
Bulgaria thing
Within similar height class
Hurt direction free

Generate a haiku with syllable pattern and newlines

$ xpg haiku+++
Greece America (1,4)
Guess brought considerable (1,1,5)
Equal leave over (2,1,2)

Generate a haiku with extended words

$ xpg -e haiku
Miss February / Consonant condition grown / Dionysus slept

Generate a password with 20 any characters

$ xpg aaaaaaaaaaaaaaaaaaaa
fE6H}ax<h?,4oILFFn;3

Same as the previous example, but shorter

This works because a character-only pattern is padded to the minimum length with the last character.

$ xpg a -m 20
pi*;,h~JVyd=J3K6I[jz

Generate 3 passwords each from a different pattern

$ xpg wwww WWWW TTTT
expressseeddoublehome
ROLLEDEVERYLIFEESCAPE
SameFlowDescribeCould

Generate a password with words with 1, 2, 3, 4, and 5 syllables

$ xpg '{a:1}-{W:a:2}-{T:a:3}-{olympian:4}-{T:ext:5}'
eggs-OSLO-Uranus-aphrodite-Northcarolina

List the words in Color / {color}

$ xpg -L '{color}'
black
blue
brown
gray
green
white
yellow

List the words in Color / {color} in uppercase

$ xpg -L '{W:color}'
BLACK
BLUE
BROWN
GRAY
GREEN
WHITE
YELLOW

List the words in Color / {color} in title case

$ xpg -L '{T:color}'
Black
Blue
Brown
Gray
Green
White
Yellow

Count the words in Color / {color}

$ xpg -L '{color}' |wc -l
7

List the words in Color / {color} and Element / {W:el}

$ xpg -L '{color}' '{W:el}'
black
blue
brown
gray
green
white
yellow
GOLD
IRON
LEAD
MERCURY
OXYGEN
SILVER

Count words

$ xpg -L |wc -l
1257

Count words with extended

$ xpg -Le |wc -l
1403

Configuration

See config.json or use -d for the default configuration compiled into the binary executable.

If another file is placed at any of the following locations or the path provided via the -C option at runtime, it will be used instead.

  • Linux: /home/username/.config/xpg/config.json
  • Windows: C:\Users\username\AppData\Roaming\qtfkwk\xpg\config\config.json
  • macOS: /Users/username/Library/Application Support/com.qtfkwk.xpg/config.json

WordKinds

  • AllExtended / {a.ext}
    • All / {a}
      • Adjective / {adj}
        • Color* / {color}
        • Nationality / {nat}
      • Adverb / {adv}
      • Conjunction / {conj}
      • Interjection / {i}
      • Noun / {n}
        • PluralNoun / {n.pl}
        • Pronoun / {n.pro}
        • SingularNoun / {n.s}
          • Astronomy / {ast}
            • Moon / {moon}
            • Planet / {planet}
          • Color* / {color}
          • Day / {day}
          • Month / {mon}
          • ProperNoun / {n.prop}
            • Element / {el}
            • Name / {name}
              • FemaleName / {fname}
              • MaleName / {mname}
            • Place / {place}
              • City / {city}
              • Continent / {cont}
              • Country / {country}
              • UsState / {us-state}
            • Mythology / {myth}
              • GreekMyth / {greekmyth}
                • Olympian / {olympian}
                • Chthonic / {chthonic}
              • RomanMyth / {romanmyth}
      • Preposition / {prep}
      • Verb / {v}
        • AuxiliaryVerb / {v.aux}
        • IntransitiveVerb / {v.int}
        • TransitiveVerb / {v.tr}
        • VerbPast / {v.past}
    • Extended / {ext}
      • Noun / {n}
        • SingularNoun / {n.s}
          • Astronomy / {ast}
            • Moon / {moon}
              • MarsMoon / {marsmoon}
              • JupiterMoon / {jupitermoon}
              • SaturnMoon / {saturnmoon}
              • UranusMoon / {uranusmoon}
              • NeptuneMoon / {neptunemoon}

Notes

  1. WordKind / {sub}

  2. It is only necessary to set the most descriptive WordKind(s) since they are automatically included in the larger word kinds.

  3. The characters object value must contain the C, c, and d keys with non-empty values. Additional keys/values can be added and used.

  4. {sub}s produce lowercase words by default, but if prefixed with W: or T: words will be uppercase or title case, respectively: i.e. {W:sub} or {T:sub} (replace sub with an actual {sub} name above).

  5. {sub}s include all words by default, but if suffixed with :N where N is a number, it will only include words with that number of syllables: i.e. {sub:N} (replace sub with an actual {sub} name above and N with the desired number of syllables ~1-5).

Changelog

  • 0.1.0 (2019-09-08): Store wordlist as constant and operate on it without copying; select N words without repetition via choose_multiple; tests; benchmark various implementations; xpg function; xpg! macro to enable optional word count argument; command line interface via clap
    • 0.1.1 (2019-09-08): Minor fixes
    • 0.1.2 (2019-09-08): Minor fixes
  • 0.2.0 (2019-09-09): Expose xpg! macro; improve documentation
  • 0.3.0 (2022-10-01): Update dependencies; add digits and symbols options
    • 0.3.1 (2022-10-01): Fix readme
  • 0.4.0 (2022-10-02): Add --lowercase, --uppercase, and --any options; enable --words option to be zero if --any option is greater than zero; enable infinite passwords via -c 0
  • 0.5.0 (2022-10-13): Add --keychain and --code-name options
  • 0.6.0 (2023-11-22): Remove num and factorial crate dependencies; improve permutations function; update dependencies; apply clippy fixes and cargo fmt; reorganize
    • 0.6.1 (2023-11-22): Fix readme
  • 0.7.0 (2023-11-24): Complete redesign
  • 0.8.0 (2023-11-25): Remove benchmark; simplify cli options; add -r and -C options; restore -c 0 functionality; add codename-series special pattern; add word kind subpatterns; enable external runtime configuration via new Config struct
    • 0.8.1 (2023-11-25): Fix -C option
  • 0.9.0 (2023-11-26): Add extended words; enable multiple patterns; add -e and -L options; make -d dump the loaded not default configuration
  • 0.10.0 (2023-11-27): Add syllables and haiku* special patterns; fix the codename series algorithm; make olympian/chthonic kinds extended; update dependencies
  • 0.11.0 (2023-11-28): Add bat pager on *nix
  • 0.12.0 (2023-11-29): Fix haiku algorithm; updated dependencies
  • 0.13.0 (2023-12-01): Add/fix months; fix dump; update dependencies
  • 0.14.0 (2023-12-11): Implement Default for Config; updated dependencies
    • 0.14.1 (2024-04-04): Update dependencies; fix changelog

References

Dependencies

~4–16MB
~179K SLoC