password

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCharset = errors.New("invalid charset: no characters available for password generation")
)

Functions

func Generate

func Generate(options ...GenerateOption) (string, error)

Generate creates a random password based on the specified options

func MustGenerate

func MustGenerate(options ...GenerateOption) string

MustGenerate is a helper that wraps Generate and panics if an error occurs

func Verify

func Verify(password string, options ...VerifyOption) error

Verify Validate password against common criteria

Types

type GenerateConfig

type GenerateConfig struct {
	Length        int
	UseUpper      bool
	UseLower      bool
	UseNumbers    bool
	UseSpecial    bool
	CustomCharset string
	ExcludeChars  string
}

GenerateConfig holds password generation settings

type GenerateOption

type GenerateOption func(*GenerateConfig)

GenerateOption is a function that modifies GenerateConfig

func GenerateWithCustomCharsetOption

func GenerateWithCustomCharsetOption(charset string) GenerateOption

GenerateWithCustomCharsetOption sets a custom character set for password generation

func GenerateWithExcludedCharsOption

func GenerateWithExcludedCharsOption(chars string) GenerateOption

GenerateWithExcludedCharsOption specifies characters to exclude from password generation

func GenerateWithLengthOption

func GenerateWithLengthOption(length int) GenerateOption

GenerateWithLengthOption sets the desired length for the generated password

func GenerateWithoutLowerOption

func GenerateWithoutLowerOption() GenerateOption

GenerateWithoutLowerOption excludes lowercase letters from password generation

func GenerateWithoutNumbersOption

func GenerateWithoutNumbersOption() GenerateOption

GenerateWithoutNumbersOption excludes numbers from password generation

func GenerateWithoutSpecialOption

func GenerateWithoutSpecialOption() GenerateOption

GenerateWithoutSpecialOption excludes special characters from password generation

func GenerateWithoutUpperOption

func GenerateWithoutUpperOption() GenerateOption

GenerateWithoutUpperOption excludes uppercase letters from password generation

type VerifyConfig

type VerifyConfig struct {
	MinLength        int
	MaxLength        int
	RequireUppercase bool
	RequireLowercase bool
	RequireNumbers   bool
	RequireSpecial   bool
}

VerifyConfig holds password validation settings

type VerifyOption

type VerifyOption func(*VerifyConfig)

VerifyOption is a function that modifies VerifyConfig

func VerifyWithMaxLengthOption

func VerifyWithMaxLengthOption(length int) VerifyOption

VerifyWithMaxLengthOption sets maximum password length

func VerifyWithMinLengthOption

func VerifyWithMinLengthOption(length int) VerifyOption

VerifyWithMinLengthOption sets minimum password length

func VerifyWithoutLowercaseOption

func VerifyWithoutLowercaseOption() VerifyOption

VerifyWithoutLowercaseOption removes lowercase requirement

func VerifyWithoutNumbersOption

func VerifyWithoutNumbersOption() VerifyOption

VerifyWithoutNumbersOption removes numbers requirement

func VerifyWithoutSpecialOption

func VerifyWithoutSpecialOption() VerifyOption

VerifyWithoutSpecialOption removes special characters requirement

func VerifyWithoutUppercaseOption

func VerifyWithoutUppercaseOption() VerifyOption

VerifyWithoutUppercaseOption removes uppercase requirement

Jump to

Keyboard shortcuts

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