Skip to content

A very flexible random password generator based on a regexp-like pattern, written in Golang

License

Notifications You must be signed in to change notification settings

ilius/repassgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Summary

This program generates fully customizable random passwords, with almost any desired pattern or length, using the same syntax as Regular Expressions for character classes (POSIX-style), repetition ({N} or {M,N}) and capturing groups ((...)).

See examples for clarity.

Build and install

Run:

go get github.com/ilius/repassgen

This will compile and then copy repassgen executable file to $GOPATH/bin/ directory.

If you just want to compile without installing it

go get -d github.com/ilius/repassgen
cd $GOPATH/src/github.com/ilius/repassgen
go build

Then repassgen binary file will be created in current directory.

Features of regexp

  • Simple repetition: {N}
  • Range repetition: {M,N}
  • Manual character range, like [a-z1-579]
  • Repeatable groups with (...){N}, like ([a-z]{2}[1-9]){3}
  • [:alnum:] Alphanumeric characters
  • [:alpha:] Alphabetic characters
  • [:word:], [:w:] or \w: Word characters (letters, numbers and underscores, same as [a-zA-Z0-9_])
  • [:upper:] Uppercase letters
  • [:lower:] Lowercase letters
  • [:graph:] Visible characters
  • [:print:] Visible characters and spaces (anything except control characters)
  • [:digit:] or \d Digits
  • [:xdigit:] Hexadecimal digits
  • [:punct:] Punctuation (and symbols).
  • [:space:] All whitespace characters, including line breaks
  • [:blank:] Space and tab
  • [:cntrl:] Control characters
  • [:ascii:] ASCII characters
  • Unicode code points, like [\u00e0-\u00ef]{5}
  • Group references \1, \2, etc

Aditional Features (not part of regexp)

  • Combined multiple named/manual character classes, for example:
    • [:digit:a-m]
    • [:digit::alpha:] = [:alnum:]
  • [:b32:] Crockford's Base32 alphabet (lowercase)
  • [:B32:] Crockford's Base32 alphabet (uppercase)
  • [:B32STD:] Standard Base32 alphabet (uppercase)
  • [:b64:] Standard Base64 alphabet
  • [:b64url:] URL-safe Base64 alphabet
  • $base64(...) Base64 encode function (input is hex-encoded)
  • $base64url(...) URL-safe Base64 encode function (input is hex-encoded)
  • $base32(...) Crockford's Base32 encode function (lowercase) (input is hex-encoded)
  • $BASE32(...) Crockford's Base32 encode function (uppercase) (input is hex-encoded)
  • $base32std(...) Standard Base32 encode function (uppercase, with no padding) (input is hex-encoded)
  • $hex(...) Hex encode function (lowercase)
  • $HEX(...) Hex encode function (uppercase)
  • Show entropy of pattern
    • Use repassgen -entropy 'PATTERN' command
    • Indicates strength of generated passwords, the higher the better
    • We recommand at least 47 bits (equal to 8 alphanumeric: [:alnum:]{8})
    • Entropy of pattern is more important than entropy of password, if you re-use patterns
  • $hex2dec(...) Convert hexadecimal number to decimal number
  • $escape(...) Escape unicode characters, non-printable characters and double quote
  • $?(...) Randomly include or omit the string/pattern (%50 chance, adds 1 bit to entropy)
  • $bip39word(N) Generate N words from BIP-39 English mnemonic words
  • $bip39encode(...) Encode hex-encoded bytes into some BIP-39 English mnemonic words
  • $date(2000,2020,-) Generate a random date in the given year range
  • $space(...) Adds spaces between each two characters of string (generated from given pattern)
  • $expand(|...) Adds | (for example) between each two characters (similar to $space)
  • $rjust(PATTERN,N,X) Justify to right, N is width (N>=1), X is the character to fill
  • $ljust(PATTERN,N,X) Justify to left, similar to $rjust
  • $center(PATTERN,N,X) Justify to center, similar to $rjust
  • $pyhex(...) Convert hex-encoded bytes to Python bytes with hex values (like b'\x74\x65\x73\x74')
  • $romaji(...) Converts Japanese hiragana/katakana string to Latin

Examples

  • Alphanumeric password with length 12

    $ repassgen '[:alnum:]{12}'
    q8nrqhPQFNqj
  • Alphabetic password with length 12

    $ repassgen '[:alpha:]{12}'
    wiADcFkhpjsk
  • Lowercase alphabetic password with length 16

    $ repassgen '[:lower:]{16}'
    rnposblbuduotibe
  • Uppercase alphabetic password with length 16

    $ repassgen '[:upper:]{16}'
    TQZZJHKQRKETOFNZ
  • Numeric password with length 8

    $ repassgen '[:digit:]{8}'
    47036294
  • A custom combination: 7 uppercase, space, 7 lowercase, space, 2 digits

    $ repassgen '[:upper:]{7} [:lower:]{7} [:digit:]{2}'
    UOHMGVM toubgvs 73
  • Password with length 12, using only Base64 characters

    $ repassgen '[:b64:]{12}'
    6+BA71WCy90I
  • Password with length 12, using only URL-safe Base64 characters

    $ repassgen '[:b64url:]{12}'
    j15w_qTncikR
  • Password with length 16, using only Crockford's Base32 characters (lowercase)

    $ repassgen '[:b32:]{16}'
    zmt87n9hpcd2w28h
  • Password with length 16, using only Crockford's Base32 characters (uppercase)

    $ repassgen '[:B32:]{16}'
    HJ48VSR4Y0DHQ9EV
  • Password with length 16, using Crockford's Base32 characters and punctuations

    $ repassgen '[:b32::punct:]{16}'
    20s:z.5mbwws474y
  • Specify character range manually: lowercase alphebetic with length 16

    $ repassgen '[a-z]{16}'
    qefqiocrabpiaags
  • Specify character range manually: alphanumeric with length 12

    $ repassgen '[a-zA-Z0-9]{12}'
    XcwDAagzMlwv
  • Include non-random characters in the password (here: Test / , .)

    $ repassgen 'Test-[:alpha:]{4}/[:alpha:]{4},[:alpha:]{4}.[:alpha:]{4}'
    Test-Jcis/uLwq,SazR.CEFJ
  • A 16-digit number similar to a credit card number

    repassgen '[:digit:]{4}-[:digit:]{4}-[:digit:]{4}-[:digit:]{4}'
    3996-9634-1459-0656
  • Alphabetic password with a length between 12 and 16 characters

    $ repassgen '[:alpha:]{12,16}'
    uamePKmuUUUcI
  • Gerenate random bytes, then run Base64 encode function

    $ repassgen '$base64($byte(){12})'
    bsOuN8KuRsOFw5jClkDDjMOrFA==
  • Gerenate random bytes, then run Crockford's Base32 encode function

    $ repassgen '$base32($byte(){12})'
    c51e2kk1aafe3jngm3gxqrazpwqva
  • Use - or [ or ] inside [...]

    $ repassgen '[.\- ]{50}'
    - .-.-- --.------- --.. -.---.-.. -- --..-..  .---
    $ repassgen '[a-z\[\]\-]{20}'
    nylhjcdq-qcaajvpcxuo
  • Use whitespace characters like newline or tab (inside or outside [...])

    $ repassgen '[a-z\t]{5}\t[a-z\t]{5}\n[a-z\t]{10}'
    caelk	zccqm
    zpbgjba	pm
  • Generate 12 random mnemonic words from BIP-39 English words

    $ repassgen '$bip39word(12)'
    cinnamon purity funny pigeon arrive equal foil alter life accident bar roast
  • Generate 16 random bytes, then encode it to BIP-39 English mnemonic words

    $ repassgen '$bip39encode($byte(){16})'
    useful come fall plunge breeze side skill another boil expose essence about

About

A very flexible random password generator based on a regexp-like pattern, written in Golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published