Help us shape the future of Go! Take the 2026 Go Developer Survey

phraser

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 5 Imported by: 0

README

💬 phraser

GoDoc

Phraser generates human readable passphrases from customizable word lists.

These passphrases are great for use as temporary passwords or whenever you need a set of user-friendly random words strung together.

Install

go get github.com/groundbreaker/phraser

Usage

import (
  "fmt"

  "github.com/groundbreaker/phraser"
)

func main() {
  p := phraser.New()
  phrase := p.GeneratePhrase()
  fmt.Println(phrase.Passphrase())
}

Documentation

Overview

Package phraser generates human readable passphrases from customizable word lists. These passphrases are great for use as temporary passwords or whenever you need a set of user-friendly random words.

Example
package main

import (
	"fmt"

	"github.com/groundbreaker/phraser"
)

func main() {
	p := phraser.New()
	phrase := p.GeneratePhrase()
	fmt.Println(phrase.Passphrase())
}
Example (Override)
package main

import (
	"fmt"

	"github.com/groundbreaker/phraser"
)

func main() {
	// Override the Default* vars before calling phraser.New()
	// Use your own []string values, or use phraser.ParseWordList to laod it from a file.
	phraser.DefaultSymbol = "#"
	phraser.DefaultAdjectives = []string{"awesome"}
	phraser.DefaultNouns = []string{"robots"}

	p := phraser.New()
	// You can also override values on the instance of phraser.
	p.Adjectives = []string{"amiable"}

	phrase := p.GeneratePhrase() // this sets the random values

	// You can override the choosen values here as well.
	phrase.Number = 42
	phrase.Symbol = "?"

	fmt.Println(phrase.Passphrase())
}
Output:
Amiable42Robots?

Index

Examples

Constants

View Source
const VERSION = "v1.0.2"

VERSION returns the SemVer for Package phraser.

Variables

View Source
var DefaultAdjectives = []string{"adaptable", "adventurous", "affable", "affectionate", "agreeable", "ambitious", "amiable", "amusing", "brave", "bright", "calm", "careful", "charming", "communicative", "compassionate ", "conscientious", "considerate", "convivial", "courageous", "courteous", "creative", "daring", "decisive", "determined", "diligent", "diplomatic", "discreet", "dynamic", "easygoing", "emotional", "empathetic", "energetic", "enthusiastic", "exuberant", "exuberant", "faithful", "fearless", "forceful", "friendly", "funny", "generous", "gentle", "gregarious", "helpful", "honest", "humorous", "imaginative", "impartial", "independent", "intelligent", "intuitive", "inventive", "kind", "loving", "loyal", "modest", "neat", "nice", "passionate", "patient", "persistent", "persistent ", "philosophical", "pioneering", "placid", "plucky", "polite", "powerful", "practical", "profitable", "quick", "rational", "reliable", "reserved", "resourceful", "sensible", "sensitive", "shy", "sincere", "sociable", "strong", "sympathetic", "thoughtful", "tidy", "unassuming", "understanding", "versatile", "warmhearted", "willing", "witty"}

DefaultAdjectives is a list of adjectives that phraser will use by default.

View Source
var DefaultNouns = []string{"animals", "artists", "baskets", "bottles", "brothers", "champs", "children", "circles", "dangers", "details", "doors", "droids", "dwarves", "engines", "events", "experts", "feelings", "freezers", "friends", "geese", "glasses", "graffiti", "groups", "harbors", "humans", "islands", "jellies", "journeys", "judges", "letters", "linens", "loaves", "machines", "minerals", "minutes", "moments", "months", "mornings", "nations", "numbers", "offspring", "opinions", "papers", "people", "pictures", "places", "planes", "plants", "purposes", "quizzes", "reasons", "rewards", "rivers", "roads", "robots", "scarves", "scissors", "shades", "sisters", "sounds", "soups", "spoons", "springs", "squares", "stamps", "stones", "students", "summers", "systems", "tables", "tails", "tastes", "teachers", "things", "thinkers", "thoughts", "times", "trains", "trucks", "values", "watches", "weeks", "whistles", "windows", "winters", "wires", "worlds", "worms", "years", "zebras"}

DefaultNouns is a list of nouns that phraser will use by default.

View Source
var DefaultSymbol = "!"

DefaultSymbol will be used when making Phrases.

Functions

func NewRNG

func NewRNG() *rand.Rand

NewRNG returns a newly seeded random number generator.

func ParseWordList

func ParseWordList(path string) []string

ParseWordList reads the words from the given path to a word list file. It returns a slice containing the words found in that file.

A word list should just be a plain text file with one word per line.

Types

type Phrase

type Phrase struct {
	Adjective string
	Number    int
	Noun      string
	Symbol    string
}

Phrase contains the phrase parts and the ability to concatentate the parts into a passphrase.

func (*Phrase) Passphrase

func (phrase *Phrase) Passphrase() string

Passphrase contcatenates the phrase parts and returns a passphrase in the form of: AdjectiveNumberNounSymbol, e.g. "Amiable42Robots!".

type Phraser

type Phraser struct {
	Adjectives []string
	Nouns      []string
	RNG        *rand.Rand
}

Phraser has two word lists, one for Adjectives and one for Nouns. It uses these words when creating passphrases.

func New

func New() *Phraser

New returns a new instance of Phraser using the DefaultAdjectives and DefaultNouns. You can override these exported vars before calling New() to use your own word list.

func (*Phraser) GeneratePhrase

func (phraser *Phraser) GeneratePhrase() *Phrase

GeneratePhrase genereates and returns a new Phrase.

func (*Phraser) RandomWord

func (phraser *Phraser) RandomWord(words []string) string

RandomWord returns a random word from the given list.

Jump to

Keyboard shortcuts

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