passwordGenerator

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: GPL-3.0 Imports: 5 Imported by: 1

README

golang-passwordGenerator

This package allows cryptographically random passwords to be generated.

Go Reference Go Report Card

Example

package main

import (
	"fmt"

	passwordGenerator "github.com/theTardigrade/golang-passwordGenerator"
)

func main() {
	pg := passwordGenerator.New(
		passwordGenerator.Options{
			Len:                     128,
			IncludeUpperCaseLetters: true,
			IncludeLowerCaseLetters: true,
			IncludeDigits:           true,
			IncludeRunesList: []rune{
				'!', '?', '-', '_', '=', '@', '$',
				'#', '(', ')', '[', ']', '{', '}',
				'<', '>', '+', '/', '*', '\\', '/',
				':', ';', '&', '\'', '"', '%', '^',
				'🙂', '🙃',
			},
			ExcludeAmbiguousRunes: true,
            ExcludeRunesList:      []rune{'a', 'b'},
		},
	)

	passwords, err := pg.GenerateMany(5)
	if err != nil {
		panic(err)
	}

	for _, p := range passwords {
		fmt.Println(p)
	}
}

Support

If you use this package, or find any value in it, please consider donating:

ko-fi

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAvailableRunes = errors.New("no runes are available for password-generation")

ErrNoAvailableRunes is used if the number of runes that can be randomly selected when generating passwords is zero.

Functions

This section is empty.

Types

type Data

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

Data is used to generate passwords, by calling the appropriate method on it. The New function is used to create a pointer to a Data struct.

func New

func New(options Options) *Data

New returns a pointer to a Data struct that is used only to generate passwords. An options argument determines exactly how the passwords should be generated.

func (*Data) AvailableRunes added in v1.1.0

func (d *Data) AvailableRunes() []rune

AvailableRunes returns a freshly allocated slice containing all of the runes that can be randomly selected when generating passwords. These runes are determined by the options contained in the Data struct.

func (*Data) AvailableRunesCount added in v1.1.0

func (d *Data) AvailableRunesCount() int

AvailableRunesCount returns the number of runes that can be randomly selected when generating passwords. These runes are determined by the options contained in the Data struct. If the number of runes is zero, no passwords can be successfully generated.

func (*Data) Generate

func (d *Data) Generate() (password string, err error)

Generate creates a single password made up of random runes. The password will conform to the options contained in the Data struct. An error is also returned from Generate, which will be non-nil if the random-number generator is not working, meaning that a password cannot be succesfully generated, or if the options in the Data struct determine that there are no available runes to be randomly selected when generating passwords.

func (*Data) GenerateMany

func (d *Data) GenerateMany(n int) (passwords []string, err error)

GenerateMany creates many passwords made up of random runes. The function's single argument will determine exactly how many passwords are generated. Any passwords will conform to the options contained in the Data struct. An error is also returned from GenerateMany, which will be non-nil if the random-number generator is not working, meaning that one of the passwords cannot be succesfully generated, or if the options in the Data struct determine that there are no available runes to be randomly selected when generating passwords.

type Options

type Options struct {
	Len                     int
	IncludeUpperCaseLetters bool
	IncludeLowerCaseLetters bool
	IncludeDigits           bool
	ExcludeAmbiguousRunes   bool
	IncludeRunesList        []rune
	ExcludeRunesList        []rune
}

Options is passed to the New function to determine exactly how any passwords should be generated by the Data struct. The Len field determines the length of any passwords that are generated, while the other fields determine which runes are available to be chosen at random when generating passwords.

Jump to

Keyboard shortcuts

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