Skip to content

Instantly share code, notes, and snippets.

@peccu
Created April 17, 2018 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peccu/ebc0cecfc8dd68bdc4d53633897e3dde to your computer and use it in GitHub Desktop.
Save peccu/ebc0cecfc8dd68bdc4d53633897e3dde to your computer and use it in GitHub Desktop.
generate password command using sethvargo/go-password

genpass

Install

  • go get github.com/sethvargo/go-password
  • git clone this repo
  • go build path/to/genpass.go
  • move genpass to your PATH
package main
import (
// "regexp"
"fmt"
"github.com/sethvargo/go-password/password"
)
func main() {
// Generate a password that is 64 characters long with 10 digits, 10 symbols,
// allowing upper and lower case letters, disallowing repeat characters.
orig, err := password.Generate(8, 2, 2, false, false)
if err != nil {
fmt.Println(err)
}
fmt.Print(orig)
// // GitBucket can't use some symbols.
// orig, err := password.Generate(64, 10, 20, false, false)
// // Remove some symbols from generated string
// r := regexp.MustCompile("[^a-zA-Z0-9\\-_.]")
// res := r.ReplaceAllString(orig, "")[:8]
// fmt.Print(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment