password

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

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

	// UpperLetters is the list of uppercase letters.
	UpperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

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

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

Variables

This section is empty.

Functions

func Generate

func Generate(length int, useLetters bool, useSpecial bool, useNum bool) (string, error)

func GeneratePassword(length int, useLetters bool, useSpecial bool, useNum bool) string {

Types

type Generator

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

Generator is the stateful generator which can be used to customize the list of letters, digits, and/or symbols.

func NewGenerator

func NewGenerator(i *GeneratorInput) (*Generator, error)

NewGenerator creates a new Generator from the specified configuration. If no input is given, all the default values are used. This function is safe for concurrent use.

func (*Generator) Generate

func (g *Generator) Generate(length int, useDigit bool, useSymbol bool, useUpper bool, useLower bool, allowRepeat bool) (string, error)

Generate generates a password with the given requirements. length is the total number of characters in the password. numDigits is the number of digits to include in the result. numSymbols is the number of symbols to include in the result. noUpper excludes uppercase letters from the results. allowRepeat allows characters to repeat.

The algorithm is fast, but it's not designed to be performant; it favors entropy over speed. This function is safe for concurrent use.

type GeneratorInput

type GeneratorInput struct {
	LowerLetters string
	UpperLetters string
	Digits       string
	Symbols      string
	Reader       io.Reader // rand.Reader by default
}

GeneratorInput is used as input to the NewGenerator function.

type PasswordGenerator

type PasswordGenerator interface {
	Generate(int, int, int, bool, bool) (string, error)
}

Jump to

Keyboard shortcuts

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