randstring

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLength = errors.New("length must be greater than 0")
	ErrEmptyAlphabet = errors.New("alphabet must not be empty")
)
View Source
var DefaultPasswordPolicy = PasswordPolicy{
	MinLowercase: 2,
	MinUppercase: 2,
	MinNumeric:   2,
	MinSpecial:   2,
	MinLength:    12,
}

Functions

func New

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

New returns a securely generated random string of the given length.

func NewWithAlphabet

func NewWithAlphabet(n int, alphabet string) ([]byte, error)

NewWithAlphabet returns a securely generated random string using the provided alphabet.

func NewWithPolicy

func NewWithPolicy(p PasswordPolicy) ([]byte, error)

NewWithPolicy generates a random password that satisfies the given PasswordPolicy.

Types

type PasswordPolicy

type PasswordPolicy struct {
	MinLowercase int // MinLowercase is the minimum number of lowercase letters required.
	MinUppercase int // MinUppercase is the minimum number of uppercase letters required.
	MinNumeric   int // MinDigits is the minimum number of numeric digits required.
	MinSpecial   int // MinSymbols is the minimum number of special symbols required.
	MinLength    int // MinLength is the minimum total length of the password.
}

Jump to

Keyboard shortcuts

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