randstr

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package: randstr provides a function to generate random strings.

Index

Constants

This section is empty.

Variables

View Source
var (
	// PasswordPolicyLength is a password policy that checks if the password is a certain length
	PasswordPolicyLength = func(length int) PasswordPolicy {
		return func(password string) bool {
			return len(password) >= length
		}
	}

	// PasswordPolicyLowercase is a password policy that checks if the password contains a lowercase character
	PasswordPolicyLowercase = func() PasswordPolicy {
		return func(password string) bool {
			return strings.ContainsAny(password, lowercase)
		}
	}

	// PasswordPolicyUppercase is a password policy that checks if the password contains an uppercase character
	PasswordPolicyUppercase = func() PasswordPolicy {
		return func(password string) bool {
			return strings.ContainsAny(password, uppercase)
		}
	}

	// PasswordPolicyNumbers is a password policy that checks if the password contains a number
	PasswordPolicyNumbers = func() PasswordPolicy {
		return func(password string) bool {
			return strings.ContainsAny(password, numbers)
		}
	}

	// PasswordPolicySymbols is a password policy that checks if the password contains a symbol
	PasswordPolicySymbols = func() PasswordPolicy {
		return func(password string) bool {
			return strings.ContainsAny(password, symbols)
		}
	}
)

Functions

This section is empty.

Types

type Generator

type Generator interface {
	Generate(int) string
}

func NewCustomGenerator

func NewCustomGenerator(letters string) Generator

NewDefaultGenerator returns a new Custom generator.

func NewDefaultGenerator

func NewDefaultGenerator() Generator

NewDefaultGenerator returns a new Default generator.

func NewIDGenerator

func NewIDGenerator() Generator

NewIDGenerator returns a new ID generator.

The ID generator creates a string using alphanumeric characters.

func NewPasswordGenerator

func NewPasswordGenerator(policies ...PasswordPolicy) Generator

NewPasswordGenerator creates a new password generator

The password generator creates a string using alphanumeric characters and symbols.

type PasswordPolicy added in v0.1.1

type PasswordPolicy func(string) bool

PasswordPolicy is a function that checks if a password is valid

Jump to

Keyboard shortcuts

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