/phrase

🗣️ simple (pass)phrase/word generator for Go

Primary LanguageGoMIT LicenseMIT

phrase

Go Reference Go Report Card Tests and Coverage codecov

phrase is a simple library that generates passphrases using pure Go and a customizable dictionary.

Warning

The default dictionary shipped with phrase is small and should not be used to generate secure passwords. Consider defining your own dictionary with a much larger selection of words before generating passwords.

Documentation

Installation

go get github.com/lukewhrit/phrase

Basic Example

package main

import "github.com/lukewhrit/phrase"

// Use the default dictionary
var p = phrase.Default

func main() {
    p.Generate(3) // => ["enrage", "juice", "await"]
    p.Generate(3).String() // => "trimmer-gothic-uncle"
}

Dictionary

A dictionary is an array of strings that is used to generate the phrases. You can call the Dictionary.Generate() function to create a passphrase. The function requires a "length" parameter and will return an array of random words. A helper function is provided on the array that allows you to convert it to a string.

A default dictionary is provided, containing ~2300 words, to generate passphrases with. It is available under the name phrase.Default. We strongly advise against using this library for generating secure passwords. A larger dictionary should be used instead.

You can define a custom dictionary by instantiating your own Dictionary object. For example:

package main

import "github.com/lukewhrit/phrase"

var p = phrase.Dictionary{"a","c","b"}

func main() {
	p.Generate(3) // => ["a", "c", "b"]
	p.Generate(3).String() // => "b-a-c"
}

Credits and License

MIT License (c) 2022-2024 Luke Whritenour. See LICENSE.

The world list is graciously taken from correcthorse by Nicolás Bevacqua, also under the MIT license.