password

package
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package password provides methods for generating secure random passwords, and shared constants such as common character sets.

Index

Constants

View Source
const (
	DigitCharacters     = "0123456789"
	UppercaseCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	LowercaseCharacters = "abcdefghijklmnopqrstuvwxyz"
	// OWASP recommended password special characters.
	SpecialCharacters        = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
	URLSafeSpecialCharacters = "-_"
)

Characters for use as character classes. Exported for utility purposes.

Variables

View Source
var ErrInvalidPasswordRejection = errors.New("password rule rejected too many passwords")

ErrInvalidPasswordRejection is returned when a password rule rejects an excessive number of passwords.

Functions

This section is empty.

Types

type CharacterClassConfiguration

type CharacterClassConfiguration struct {
	// The Characters included in this character class.
	Characters string
	// The Minimum number of characters from this character class to include in the password.
	Minimum int
}

CharacterClassConfiguration configures the character composition of the password.

type Configuration

type Configuration struct {
	/* Minimum length of the password.
	 * The actual length will be random, and in the range minimum_length <= length <= 1.5 * minimum_length.
	 * Random lengths allow for minimum complexity requirements to be met while not enforcing a strict
	 * composition (eg. exactly 2 digits, and exactly 1 special character).
	 */
	Length int
	// CharacterClasses configuration, eg. the list of characters and the minimum quantity to include.
	CharacterClasses []CharacterClassConfiguration
}

Configuration sets the properties of the generated password.

type Generator

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

Generator generates random passwords matching a rule.

func NewGenerator

func NewGenerator(passwordRule Rule) Generator

NewGenerator constructs a random password generator from a rule.

func (Generator) Generate

func (g Generator) Generate() (string, error)

Generate a new random password.

type Rule

type Rule interface {
	// Return the configuration associated with this rule.
	Config() *Configuration
	// Is the password valid?
	Valid(password []rune) bool
}

Rule is used to set the behavior of the random password generator.

Source Files

Jump to

Keyboard shortcuts

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