passgen

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: ISC Imports: 7 Imported by: 0

README

passgen

Builds Go Report Card GoDoc License

passgen is an API and command-line utility for generating passwords and passphrases.

Installation

To install the command-line utility:

git clone -b stable --depth 1 https://github.com/schultz-is/passgen.git
cd passgen
make install

To install the API for use in other projects:

go get github.com/schultz-is/passgen

Examples

Using the command-line utility
> passgen password
vt7tStRf3SfLV3V3
> passgen pw -alnsu
Bc!Eyca9pHmWuRJr
> passgen pw 5 10 --alphabet "ACGT"
ATAAG
CATTC
TTGAT
CGGAT
TGTAG
GCGAC
ACATG
TTATT
ACTAT
CCGTA
> passgen passphrase
faceless navigate scabby return snorkel cough
> passgen pp -ts.
Cranberry.Deskwork.Ramble.Energize.Gloss.Tranquil
> passgen pp 5 6 -uw words.txt
TANNING TRICKLE PRECOOK KEEP ARMHOLE
MARITIME LADYLIKE ELM UNDRAFTED BONANZA
EGOTISM MANTIS BANNER MUNICIPAL AMUSING
EVOLUTION WIRING TRACK BLURT GREYHOUND
UNTITLED RURAL SHAKINESS GEOMETRIC ARMREST
WHY OUTCLASS RIVETING OVERLORD UNFIXED
Using the API
package main

import (
	"fmt"

	"github.com/schultz-is/passgen"
)

func main() {
	passwords, err := passgen.GeneratePasswords(
		passgen.PasswordCountDefault,
		passgen.PasswordLengthDefault,
		passgen.AlphabetDefault,
	)
	if err != nil {
		panic(err)
	}

	for _, password := range passwords {
		fmt.Println(password)
	}
}

Open in Go Playground

package main

import (
	"fmt"

	"github.com/schultz-is/passgen"
)

func main() {
	passphrases, err := passgen.GeneratePassphrases(
		passgen.PassphraseCountDefault,
		passgen.PassphraseWordCountDefault,
		passgen.PassphraseSeparatorDefault,
		passgen.PassphraseCasingDefault,
		passgen.WordListDefault,
	)
	if err != nil {
		panic(err)
	}

	for _, passphrase := range passphrases {
		fmt.Println(passphrase)
	}
}

Open in Go Playground

Tests

> make test
> make cover

Benchmarks

> make benchmark
> go tool pprof prof/cpu.prof
> go tool pprof prof/mem.prof

Build

> make build
> ./dist/passgen --version

Documentation

Index

Constants

View Source
const (
	PasswordCountMin     = 1    // Fewest allowed passwords to generate.
	PasswordCountMax     = 1024 // Most allowed passwords to generate.
	PasswordCountDefault = 1    // Default number of passwords to generate.

	PasswordLengthMin     = 5    // Shortest allowed password to generate.
	PasswordLengthMax     = 1024 // Longest allowed password to generate.
	PasswordLengthDefault = 16   // Default length of password to generate.

	AlphabetLengthMin        = 2                                               // Smallest allowed alphabet.
	AlphabetLower            = "abcdefghijkmnopqrstuvwxyz"                     // Lowercase English letters, ambiguous characters removed.
	AlphabetLowerAmbiguous   = "l" + AlphabetLower                             // Lowercase English letters.
	AlphabetUpper            = "ABCDEFGHJKLMNPQRSTUVWXYZ"                      // Uppercase English letters, ambiguous characters removed.
	AlphabetUpperAmbiguous   = "IO" + AlphabetUpper                            // Uppercase English letters.
	AlphabetNumeric          = "23456789"                                      // Arabic numerals, ambiguous characters removed.
	AlphabetNumericAmbiguous = "01" + AlphabetNumeric                          // Arabic numerals.
	AlphabetSpecial          = "!@#$%^&*_-+="                                  // Selection of special characters.
	AlphabetDefault          = AlphabetLower + AlphabetUpper + AlphabetNumeric // Alphanumeric English characters, ambiguous characters removed.
	AlphabetDefaultAmbiguous = AlphabetLowerAmbiguous + AlphabetUpperAmbiguous + AlphabetNumericAmbiguous

	PassphraseCountMin     = 1    // Fewest allowed passphrases to generate.
	PassphraseCountMax     = 1024 // Most allowed passphrases to generate.
	PassphraseCountDefault = 1    // Default number of passphrases to generate.

	PassphraseWordCountMin     = 3  // Shortest word-length allowed for passphrase generation.
	PassphraseWordCountMax     = 64 // Longest word-length allowed for passphrase generation.
	PassphraseWordCountDefault = 6  // Default word-length for passphrase generation.

	PassphraseSeparatorSpace      = ' '
	PassphraseSeparatorDash       = '-'
	PassphraseSeparatorUnderscore = '_'
	PassphraseSeparatorDot        = '.'
	PassphraseSeparatorColon      = '.'
	PassphraseSeparatorDefault    = PassphraseSeparatorSpace // Default passphrase word separator.

	PassphraseCasingLower   = iota // All lowercase passphrase output.
	PassphraseCasingUpper          // All uppercase passphrase output.
	PassphraseCasingTitle          // Title casing for each passphrase word.
	PassphraseCasingNone           // No casing transformation is applied to the provided word list.
	PassphraseCasingDefault = PassphraseCasingNone

	WordListLengthMin = 2
)

Helpful defaults, limits, and options for configuring package function calls.

Variables

View Source
var (

	// WordListDefault is a set of words from EFF for use with their passphrase dice method of
	// deriving passphrases.
	// See: https://www.eff.org/dice
	WordListDefault = []string{}/* 7776 elements not displayed */

)

Functions

func GeneratePassphrases

func GeneratePassphrases(
	count uint,
	wordCount uint,
	separator rune,
	casing PassphraseCasing,
	wordList []string,
) (
	passphrases []string,
	err error,
)

GeneratePassphrases generates random passphrases based on the configuration provided by the user.

func GeneratePasswords

func GeneratePasswords(
	count uint,
	length uint,
	alphabet string,
) (
	passwords []string,
	err error,
)

GeneratePasswords generates random passwords based on the configuration provided by the user.

Types

type PassphraseCasing

type PassphraseCasing uint8

PassphraseCasing represents the casing of each word within a passphrase.

Directories

Path Synopsis
cmd
passgen command

Jump to

Keyboard shortcuts

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