/go-password

Golang library for generating cryptographically secure passwords.

Primary LanguageGoMIT LicenseMIT

Golang Password Generation Library

Build Status GoDoc

Performance-oriented library for the generation of random passwords.

Inspired by Seth Vargos go-password implementation.

Installation

$ go get -u github.com/szybia/go-password/password

cli tool for generating passwords:

$ go get -u github.com/szybia/go-password/randpw

Usage

package main

import (
	"fmt"

	"github.com/szybia/go-password/password"
)

func main() {
	//	Generate a random password of length 50
	pass, err := password.GenerateLength(50)
	if err != nil {
		panic(err)
	}
	fmt.Println(pass)
}

Output:

Rg,FCu/4{'(ZWB4HR5D~%R[vA{ITM^!i5\{pkq;VnIj?=O"CL3

You can also create your own generators with a specific character set as shown below:

//	Create generator with specified character set
g := password.NewGenerator(&password.CharSet{
	Lowercase: "abc",
	Uppercase: "ABC",
	Digits:    "012",
	Symbols:   "",
})

//	Generate a password consisting of
//	5 lowercase, uppercase letters and 5 digits
pass, err := g.Generate(5, 5, 5, 0) //  output: 1Cc1c02cAB2CBba

//  Generate a password of length 15
pass, err := g.GenerateLength(15)   //  output: a0BC1B1cbA1a10B