Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
/ go-passgen Public archive

Simple password generator written in Go

License

Notifications You must be signed in to change notification settings

marcfrederick/go-passgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-passgen

CI

⚠️ This library is not suitable for generating passwords in high-security or critical systems. Its intended use is primarily for testing and low-risk scenarios.

For more robust password generation in critical environments, consider 1Password/spg.

go-passgen is a simple, dependency-free password generator written in Go.

Installation

Ensure that your Go version is 1.13 or later and supports modules. To add go-passgen to your project, execute the following command:

go get github.com/marcfrederick/go-passgen

Alternatively, you can import it directly into your Go source files and run go get:

import "github.com/marcfrederick/go-passgen/passgen"

Usage

Below is a basic example demonstrating how to generate a password:

package main

import (
	"log"

	"github.com/marcfrederick/go-passgen/passgen"
)

func main() {
	generator, err := passgen.NewGenerator()
	if err != nil {
		log.Fatalf("failed to create generator: %v", err)
	}

	password, err := generator.Generate(16, passgen.ExcludeSymbols, passgen.ExcludeDigits)
	if err != nil {
		log.Fatalf("failed to generate password: %v", err)
	}

	log.Printf("password: %s", password)
}

The above example will generate a password with a length of 16 characters, excluding symbols and digits.

Options

By default, go-passgen utilizes the crypto/rand package for randomness. However, you can specify a different source of randomness by providing an io.Reader implementation to passgen.NewGenerator. This can be particularly useful for generating deterministic passwords in testing scenarios:

generator, err := passgen.NewGenerator(passgen.WithReader(rand.Reader))

Alternatives