gopassgen

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2018 License: MIT Imports: 3 Imported by: 2

README

gopassgen

GoDoc Go Report Card

To use it as a command-line tool or web app, install gopgcli or gopgweb

Install
go get github.com/sayanarijit/gopassgen
Available policy options
Policy Configuration Type Default
Maximum length MaxLength int 16
Minimum length MinLength int 6
Minimum lower case letters MinLowers int 0
Minimum upper case lette MinUppers int 0
Minimum digits MinDigits int 0
Minimum special characters MinSpclChars int 0
Permitted upper case letters UpperPool string ABCDEFGHIJKLMNOPQRSTUVWXYZ
Permitted lower case letters LowerPool string abcdefghijklmnopqrstuvwxyz
Permitted digits DigitPool string 0123456789
Permitted special characters SpclCharPool string !@#$%^&*()-_=+,.?/:;{}[]~
Example Usage
Generate a 16 character long password with minimum 2 digits, 2 special characters, 1 capital and 1 small letter
package main

import (
    "fmt"
    "github.com/sayanarijit/gopassgen"
)

func main() {

    p := gopassgen.NewPolicy()

    p.MaxLength = 16      // Maximum total length
    p.MinLength = 16      // Minimum total length
    p.MinDigits = 2       // Minimum digits
    p.MinSpclChars = 2    // Minimum special characters
    p.MinUppers = 1       // Minimum upper case letters
    p.MinLowers = 1       // Minimum lower case letters

    password, _ := gopassgen.Generate(p)
    fmt.Println(password)
}
Quickly generate random password of given length using given characters
package main

import (
    "fmt"
    "github.com/sayanarijit/gopassgen"
)

func main() {

    bsPassword := gopassgen.CreateRandom([]byte("ABCDwxyz1234$%^&"), 8) // Returns bytes array

    fmt.Println(string(bsPassword))
}
Generate password by shuffling given characters
package main

import (
    "fmt"
    "github.com/sayanarijit/gopassgen"
)

func main() {

    bsPassword := []byte("ABCDwxyz1234$%^&")

    gopassgen.Shuffle(bsPassword)

    fmt.Println(string(bsPassword))
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMaxLengthExceeded is returned when the sum of minimum character lengths exceeded maximum length
	ErrMaxLengthExceeded = errors.New("sum of minimum character lengths exceeded maximum password length")
)

Functions

func CreateRandom

func CreateRandom(bs []byte, length int) []byte

CreateRandom returns a random byte string of given length from given byte string

func Generate

func Generate(p Policy) (string, error)

Generate a new password based on given policy

func Shuffle

func Shuffle(bs []byte)

Shuffle the given byte string

Types

type Policy

type Policy struct {
	MinLength    int    // Minimum length of password
	MaxLength    int    // Maximum length of password
	MinLowers    int    // Minimum length of lower case letters
	MinUppers    int    // Minimum length of upper case letters
	MinDigits    int    // Minimum length of digits
	MinSpclChars int    // Minimum length of special characters
	LowerPool    string // Permitted upper case letters
	UpperPool    string // Permitted lower case letters
	DigitPool    string // Permitted digits
	SpclCharPool string // Permitted special characters
}

Policy of password to be passed in Generate() function

func NewPolicy

func NewPolicy() Policy

NewPolicy returns a default password policy which can be modified

Jump to

Keyboard shortcuts

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