pwgen

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2021 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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

ErrInvalidLenBounds represents bad minLen/maxLen values.

Functions

func BuildCharsets added in v1.2.0

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL