password

package
v0.3.37 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

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")

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

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

Functions

func Base64Decode

func Base64Decode(str string) string

Base64Decode base64 decode

func Base64Encode

func Base64Encode(str string) string

Base64Encode base64 encode

func Bcrypt

func Bcrypt(pwd string) string

Bcrypt bcrypt.Sum

func BcryptCheck

func BcryptCheck(hashedPwd, pwd string) bool

BcryptCheck check bcrypt hash

func Check

func Check(hashed, pwd string) bool

Check sha256 password check

func Gen

func Gen(pwd string) string

Gen generate the sha256 password

func Generate

func Generate(length, numDigits, numSymbols int, noUpper, allowRepeat bool) (string, error)

Generate is the package shortcut for Generator.Generate.

func Md5

func Md5(str string) string

Md5 md5.Sum

func MustGenerate

func MustGenerate(length, numDigits, numSymbols int, noUpper, allowRepeat bool) string

MustGenerate is the package shortcut for Generator.MustGenerate.

func Sha1

func Sha1(str string) string

Sha1 sha1.Sum

func Sha1Check

func Sha1Check(hashed, pwd string) bool

Sha1Check sha1 password check

func Sha1Gen

func Sha1Gen(pwd string) string

Sha1Gen generate the sha1 password

func Sha256

func Sha256(str string) string

Sha256 sha256.Sum

func Sha512

func Sha512(str string) string

Sha512 sha512.Sum

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.

func (*Generator) Generate

func (g *Generator) Generate(length, numDigits, numSymbols int, noUpper, allowRepeat bool) (string, 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.

func (*Generator) MustGenerate

func (g *Generator) MustGenerate(length, numDigits, numSymbols int, noUpper, allowRepeat bool) string

MustGenerate is the same as Generate, but panics on error.

type GeneratorInput

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

GeneratorInput is used as input to the NewGenerator function.

type PasswordGenerator

type PasswordGenerator interface {
	Generate(int, int, int, bool, bool) (string, error)
	MustGenerate(int, int, int, bool, bool) string
}

PasswordGenerator is an interface that implements the Generate function. This is useful for testing where you can pass this interface instead of a real password generator to mock responses for predicability.

Jump to

Keyboard shortcuts

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