Skip to content
Policy based password generator library for Golang
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
gopassgen.go
gopassgen_test.go

README.md

gopassgen

GoDoc Go Report Card License: MIT

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))
}
You can’t perform that action at this time.