8 releases (4 breaking)

0.5.0 Oct 13, 2022
0.4.0 Oct 2, 2022
0.3.1 Oct 1, 2022
0.2.0 Sep 9, 2019
0.1.2 Sep 8, 2019

#459 in Command line utilities

50 downloads per month

MIT license

115KB
1.5K SLoC

About

xkcd-style password generator

Features

  • Balanced code verbosity, comments, documentation, tests, benchmarks, external dependencies
  • CLI utility
  • Rust library, function, macro

Usage

CLI

$ xpg -h
xkcd-style password generator

Usage: xpg [OPTIONS]

Options:
      --analyze             Analyze
  -w, --words <NUMBER>      Number of words in password [default: 4]
  -c, --count <NUMBER>      Number of passwords [default: 1]
  -d, --digits <NUMBER>     Append digits [default: 0]
  -s, --symbols <NUMBER>    Append symbols [default: 0]
  -l, --lowercase <NUMBER>  Append lowercase letters [default: 0]
  -u, --uppercase <NUMBER>  Append uppercase letters [default: 0]
  -a, --any <NUMBER>        Append *any* characters (digits, symbols, lowercase,
                            uppercase) [default: 0]
      --keychain            Generate keychain-style password(s)
      --code-name           Generate code name(s)
  -h, --help                Print help information
  -V, --version             Print version information
$ xpg -V
xpg 0.5.0

Examples

$ xpg
DoesFlowersStateSeptember
$ xpg -c 10
FenceWhichYellowGreece
HawaiiUranusValueMoscow
DistantMaybeFamilyCents
DifferentInsteadCommonWheels
FurtherDreamGoodbyeService
MeatSettledRememberThrow
SubstancesItselfRushEscape
IndeedShoutedGrownWill
BlockPerhapsUranusLess
DoubleNeitherActionHunger
$ xpg -w 8
ColombiaPartyFourSceneEffortListenCornShore
$ xpg -w 8 -c 10
ShortBecauseFirmNeedlePeopleHungerPlainAnother
MainPressSmallLordLakeTookTellWrote
DesertRaisedMonthHouseDropWornPromiseNumeral
BranchesSouthTouchTakeAfterBreakJumpedSimilar
AcrossJamaicaExerciseAlongPageStudentsStudySpeak
RockWagonBerlinColombiaItselfFourContainManner
LeftToneAlaskaElementsReceivedHistoryMainReturn
CourseJulyMatterRaceParticularHeavySuddenSpring
ChildhoodDollarAdjectiveKeptGreenForeverGaveSuppose
JumpedLowerDoubleGraveBearThinAllowSeven
$ xpg -w 2 -d 3
DuskSpecial597
$ xpg -w 2 -s 2
GovernChief(!
$ xpg -w 2 -d 1 -s 1
SuccessDoctor1[
$ xpg -l 2
CopenhagenTravelLondonBirdqc
$ xpg -u 2
AngryKnowSurfaceTillLT
$ xpg -a 5
WindInsideEastServeT>l<N
$ xpg -w 0 -a 20
f5@I%_CP@&{Q@(?E*t.1
$ xpg --keychain
rml4uu-dclvzu-fotlQs
$ xpg --code-name
ROOM TABLE
$ xpg --analyze
* Word list length: 1,259
* Words in password: 4
* Total permutations (without repetition): 2,500,525,503,024

    ```
    1,259! / (1,259 - 4)!
    1,259! / 1,255!
    2,500,525,503,024
    ```

Words | Permutations
---|---:
1 | 1,259
2 | 1,583,822
3 | 1,990,864,254
4 | 2,500,525,503,024
5 | 3,138,159,506,295,120
6 | 3,935,252,020,894,080,480
7 | 4,930,870,782,180,282,841,440
8 | 6,173,450,219,289,714,117,482,880
... | ...

$ xpg --analyze -w 8
* Word list length: 1,259
* Words in password: 8
* Total permutations (without repetition): 6,173,450,219,289,714,117,482,880

    ```
    1,259! / (1,259 - 8)!
    1,259! / 1,251!
    6,173,450,219,289,714,117,482,880
    ```

Words | Permutations
---|---:
1 | 1,259
2 | 1,583,822
3 | 1,990,864,254
4 | 2,500,525,503,024
5 | 3,138,159,506,295,120
6 | 3,935,252,020,894,080,480
7 | 4,930,870,782,180,282,841,440
8 | 6,173,450,219,289,714,117,482,880
... | ...

Changelog

  • 0.5.0 (2022-10-13)
    • add --keychain and --code-name options
  • 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.3.1 (2022-10-01)
    • fix readme
  • 0.3.0 (2022-10-01)
    • update dependencies
    • add digits and symbols options
  • 0.2.0 (2019-09-09)
    • expose xpg! macro
    • improve documentation
  • 0.1.2 (2019-09-08)
    • minor fixes
  • 0.1.1 (2019-09-08)
    • minor fixes
  • 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

References

Legal

Copyright 2019-2022 qtfkwk

Permission is hereby granted, free of charge, to any person obtaining a copy of 
this software and associated documentation files (the "Software"), to deal in 
the Software without restriction, including without limitation the rights to 
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
of the Software, and to permit persons to whom the Software is furnished to do 
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.

MIT License

Tests

$ cargo test

running 11 tests
test tests::xpg_cannot_return_zero_words - should panic ... ok
test tests::xpg_macro_cannot_return_zero_words - should panic ... ok
test tests::xpg_can_return_one_word ... ok
test tests::xpg_macro_can_return_one_word ... ok
test tests::xpg_can_return_three_words ... ok
test tests::xpg_can_return_four_words ... ok
test tests::default_xpg_macro_returns_four_words ... ok
test tests::xpg_macro_can_return_four_words ... ok
test tests::xpg_macro_can_return_three_words ... ok
test tests::xpg_can_return_five_words ... ok
test tests::xpg_macro_can_return_five_words ... ok

test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Dependencies

~2.5–7.5MB
~137K SLoC