password

package
v0.0.0-...-fd4fc0b Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package password provides a library for generating random passwords using the crypto/rand package.

Index

Constants

View Source
const (
	// Lowercase is the default list of lowercase letters.
	Lowercase = "abcdefghijklmnopqrstuvwxyz"

	// Uppercase is the default list of uppercase letters.
	Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	// Digits is the default list of permitted digits.
	Digits = "0123456789"

	// Symbols is the default list of symbols.
	Symbols = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
)

Variables

View Source
var (
	// ErrNegativeCharNum error is returned when a negative number of character types is requested.
	// E.g. impossible to return password with -1 total lowercase letters.
	ErrNegativeCharNum = errors.New("password with negative number of specific character types is impossible")

	// ErrTypeExceedsAvailable error is returned when a non-zero number of characters
	// of specific type is requested but the character set for that type is empty
	ErrTypeExceedsAvailable = errors.New("non-zero number of character type requested but character set is empty")

	// ErrLengthEmptyGenerator error is returned when a password of specific length is requested
	// but the generator does not have any characters, therefore no password can be generated
	ErrLengthEmptyGenerator = errors.New("password of length requested but generator character set is empty")

	// ErrNegativeLength error is returned when a password of negative length is requested
	ErrNegativeLength = errors.New("password with negative length is not possible")
)

Functions

func Generate

func Generate(numLower, numUpper, numDigits, numSymbols int) (string, error)

Generate is the package shortcut for Generator.Generate. It uses the default character set to generate a cryptographically secure random password.

func GenerateLength

func GenerateLength(length int) (string, error)

GenerateLength is the package shortcut for Generator.GenerateLength. It uses the default character set to generate a cryptographically secure random password.

Types

type CharSet

type CharSet struct {
	Lowercase string
	Uppercase string
	Digits    string
	Symbols   string
}

CharSet is used for specifying a custom character set which will be used for creating a password generator.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator is used for the generating of a cryptographically secure password with a initialized character set.

func NewGenerator

func NewGenerator(c *CharSet) *Generator

NewGenerator creates a new Generator from the specified character set. If zero value (nil) is provided then default values are used. Otherwise, the values in the CharSet are used.

func (*Generator) Generate

func (g *Generator) Generate(numLower, numUpper, numDigits, numSymbols int) (s string, err error)

Generate uses the generator character set to produce a cryptographically secure random password.

func (*Generator) GenerateLength

func (g *Generator) GenerateLength(length int) (string, error)

GenerateLength generates a password of a specified length using all characters within the generators character set.

Jump to

Keyboard shortcuts

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