passgen

package module
v0.0.0-...-f30e86b Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2015 License: MIT Imports: 11 Imported by: 1

README

passgen GoDoc

Password generator package for Go.

Documentation

Overview

Package passgen provides several cryptographicaly secure pseudorandom pass{word,phrase} generator methods.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrLength = errors.New("passgen: invalid password length")
	ErrSet    = errors.New("passgen: character set is empty")
	ErrDict   = errors.New("passgen: dictionary is empty")
)
View Source
var Base32Alphabet *base32.Encoding = base32.StdEncoding

Base32Alphabet is the encoding alphabet used by the Base32 generator function. Base32Alphabet defaults to base32.StdEncoding (see RFC 4648).

Rng is a global instance of a random reader, used by the random password generator functions in this package. Reader defaults to the cryptographically secure pseudorandom generator in crypto/rand.

Functions

func Ascii

func Ascii(n int, s CharSet) ([]byte, error)

Ascii generates a uniformly distributed random ASCII string with length n. The password space consists of printable ASCII chars and can be narrowed down with the CharSet bitmask s.

Example
password, err := Ascii(20, SetComplete&^SetSymbol)
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Generated password: %q\n", password)
Output:

func Base32

func Base32(n int) ([]byte, error)

Base32 generates a uniformly distributed random base32 string with length n.

func Diceware

func Diceware(dict io.Reader, n int, sep string) (phrase []byte, m int, err error)

Diceware selects n random words from the specified dictionary reader dict. Words are separated with the sep parameter (usually "" or " "). The dictionary source format is one word per line. Aside from the generated passphrase, the dictionary size m (i.e. number of selectable words) is returned. This can be useful for determining the entropy of the resulting passphrase (See the Entropy function).

Example
dict, err := os.Open("/usr/share/dict/words")
if err != nil {
	log.Fatal(err)
}

password, _, err := Diceware(dict, 5, "")
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Generated password: %q\n", password)
Output:

func Entropy

func Entropy(n, m int) float64

Entropy calculates password strength (in bits) of a password with length n, selected from a set of m possible symbols.

func Hex

func Hex(n int) ([]byte, error)

Hex generates a uniformly distributed random hex string (base16) with length n.

Types

type CharSet

type CharSet uint8

CharSet represents the set of printable ASCII characters. The maximum number of characters is 95. All printable characters are available in the continuous range of [32, 126].

const (
	// Bitmask flags for creating a permutation of characters sets.
	SetLower    CharSet = 1 << iota       // Lower case letters [a-z]
	SetUpper                              // Upper case letters [A-Z]
	SetDigit                              // Decimal digits [0-9]
	SetPunct                              // Punctuation chars [!"#%&'()*,-./:;?@[\]_{}]
	SetSymbol                             // Symbolic chars [$+<=>^`|~]
	SetSpace                              // White space char
	SetComplete CharSet = (1 << iota) - 1 // Set of all printable chars
)

func (CharSet) Cardinality

func (set CharSet) Cardinality() (c int)

Cardinality returns the charset Size.

Jump to

Keyboard shortcuts

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