pgen

package
v0.0.0-...-cb67029 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: AGPL-3.0 Imports: 4 Imported by: 1

Documentation

Overview

Package pgen is a password generator tool to create random passwords The idea of this package came from https://github.com/Luzifer/password

Example

Example generates 3 passwords

package main

import (
	"fmt"

	"github.com/xumak-grid/go-grid/pkg/pgen"
)

func main() {
	g := pgen.NewGenerator()
	p1, _ := g.GeneratePassword(10, true)
	p2, _ := g.GeneratePassword(15, true)
	fmt.Println(p1, p2)

	// Changing specials characters (numerics, letters, specials)
	g.CharacterTables["specials"] = "*/-$"
	p3, _ := g.GeneratePassword(20, true)
	fmt.Println(p3)
}
Output:

Index

Examples

Constants

View Source
const (
	// MinimumLength the minimum length of a password
	MinimumLength = 8
	// ErrMinLengthRequired represents the minimum length error
	ErrMinLengthRequired = customError("minimum length error " + string(MinimumLength))
	// CharacterNumerics all numbers
	CharacterNumerics = "0123456789"
	// CharacterLetters all letters
	CharacterLetters = "abcdefghijklmnopqrstuvwxyz"
	// CharacterSpecials all special characters
	CharacterSpecials = "!#$%&()*+,-_./:;=?@[]^{}~|"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// CharacterTables maps the allowed characters (numerics, letters, specials)
	CharacterTables map[string]string
	// BadCharacters define the characters that will be ignored
	BadCharacters []string
}

Generator provides methods for generating secure passwords

func NewGenerator

func NewGenerator() *Generator

NewGenerator initializes a new generator

func (*Generator) GeneratePassword

func (s *Generator) GeneratePassword(length int, special bool) (string, error)

GeneratePassword generates a new password with a given length and optional special characters in it, if length < MinimumLength will return the ErrMinLengthRequired error

Jump to

Keyboard shortcuts

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