package pwgen

import "git.sr.ht/~seirdy/moac/pwgen"

Package pwgen allows generating random passwords given charsets, length limits, and target entropy.

Index

Variables

var ErrInvalidLenBounds = errors.New("bad length bounds")

ErrInvalidLenBounds represents bad minLen/maxLen values.

Functions

func BuildCharsets

func BuildCharsets(charsetsEnumerated []string) map[string][]rune

BuildCharsets creates the charsets to use when generating passwords. It de-duplicates custom charsets and ensures that there is no overlap between different charsets. It replaces "ascii" and "latin" aliases with their individual components, and checks each charset named in charsetsNamed against entropy.Constants. Named charsets that don't correspond to entries in entropy.Constants are treated as elements of a new custom charset.

func GenPW

func GenPW(charsetsEnumerated []string, entropyWanted float64, minLen, maxLen int) (string, error)

GenPW generates a random password using characters from the charsets enumerated by charsetsEnumerated. At least one element of each charset is used. Available charsets are "lowercase", "uppercase", "numbers", "symbols", "latin1", latinExtendedA", "latinExtendedB", and "ipaExtensions". "latin" is also available: it's equivalent to specifying "latin1 latinExtendedA latinExtendedB ipaExtensions". Anything else will be treated as a string containing runes of a new custom charset to use. If entropyWanted is 0, the generated password has at least 256 bits of entropy; otherwise, it has entropyWanted bits of entropy. minLen and maxLen are ignored when set to zero; otherwise, they set lower/upper bounds on password character count and override entropyWanted if necessary. GenPW will *not* strip any characters from given charsets that may be undesirable (newlines, control characters, etc.), and does not preserve grapheme clusters.

Source Files

indexing.go pwgen.go

Version
v1.2.0 (latest)
Published
Sep 23, 2021
Platform
linux/amd64
Imports
10 packages
Last checked
1 month ago

Tools for package owners.