phrase

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 2 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = Dictionary{}/* 2286 elements not displayed */

Functions

This section is empty.

Types

type Dictionary

type Dictionary []string

func (Dictionary) Generate

func (d Dictionary) Generate(words int) Phrase

Generate a new Phrase with a given number of words

type Phrase

type Phrase []string

func (Phrase) String

func (p Phrase) String() string

Convert a Phrase to a "-"-delineated string

Jump to

Keyboard shortcuts

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