password

package module
v0.0.0-...-8788608 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 4 Imported by: 2

README

password

Build Status Coverage Status Go Report Card GoDoc

Package go-utilities-password provides a library for generating high-entropy random password strings via the crypto/rand package.

Download:

go get github.com/1800alex/go-utilities-password

Package go-utilities-password provides a library for generating high-entropy random password strings via the crypto/rand package.

forked from github.com/sethvargo/go-password/password

Most functions are safe for concurrent use.

Examples

Generate Code:

{
	res, err := Generate(64, true, true, false, false)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(res)
}

Generator Generate Code:

{
	gen, err := NewGenerator(nil)
	if err != nil {
		log.Fatal(err)
	}
	res, err := gen.Generate(64, true, true, false, false)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(res)
}

NewGenerator custom Code:

{
	gen, err := NewGenerator(&GeneratorInput{Symbols: "!@#$%^()"})
	if err != nil {
		log.Fatal(err)
	}
	_ = gen
}

NewGenerator nil Code:

{
	gen, err := NewGenerator(nil)
	if err != nil {
		log.Fatal(err)
	}
	_ = gen
}

Documentation

Overview

Package go-utilities-password provides a library for generating high-entropy random password strings via the crypto/rand package.

forked from github.com/sethvargo/go-password/password

Most functions are safe for concurrent use.

Index

Examples

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

View Source
var (
	// ErrExceedsTotalLength is the error returned with the number of digits and
	// symbols is greater than the total length.
	ErrExceedsTotalLength = errors.New("number of digits and symbols must be less than total length")

	// ErrLettersExceedsAvailable is the error returned with the number of letters
	// exceeds the number of available letters and repeats are not allowed.
	ErrLettersExceedsAvailable = errors.New("number of letters exceeds available letters and repeats are not allowed")
)

Functions

func Generate

func Generate(length int, allowDigits, allowSymbols, noUpper, allowRepeat bool) (result string, err error)

Generate is the package shortcut for Generator.Generate.

Example
res, err := Generate(64, true, true, false, false)
if err != nil {
	log.Fatal(err)
}
log.Print(res)
Output:

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.

Example (Custom)
// Customize the list of symbols.
gen, err := NewGenerator(&GeneratorInput{
	Symbols: "!@#$%^()",
})
if err != nil {
	log.Fatal(err)
}

_ = gen // gen.Generate(...)
Output:

Example (Nil)
// This is exactly the same as calling "Generate" directly. It will use all
// the default values.
gen, err := NewGenerator(nil)
if err != nil {
	log.Fatal(err)
}

_ = gen // gen.Generate(...)
Output:

func (*Generator) Generate

func (g *Generator) Generate(length int, allowDigits, allowSymbols, noUpper, allowRepeat bool) (result string, err 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.

Example
gen, err := NewGenerator(nil)
if err != nil {
	log.Fatal(err)
}

res, err := gen.Generate(64, true, true, false, false)
if err != nil {
	log.Fatal(err)
}
log.Print(res)
Output:

type GeneratorInput

type GeneratorInput struct {
	LowerLetters string
	UpperLetters string
	Digits       string
	Symbols      string
}

GeneratorInput is used as input to the NewGenerator function.

Jump to

Keyboard shortcuts

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