passgen

package module
v0.0.0-...-d36ab36 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2015 License: MIT Imports: 12 Imported by: 0

README

passgen

A password and passphrase generation library and utility. Passgen includes a builtin dictionary so you can get up and running, but you can replace it if you need.

There are two parts to this, a go library that can easily be imported and used, and a command utility.

passgen CLI

Install

Getting passgen

There are two ways to install passgen. The latest binaries are here, or you can build it yourself.

Building passgen
$ go get github.com/JustinJudd/passgen/passgen
Using passgen

You can view a full list of commands using $ passgen help and $ passgen help [command] but the following examples cover most use cases

Generate a password with

$ passgen password

Generate a numeric password (just numbers) of 4 characters

$ passgen password --type n --min=4 --max=4

Generate a passphrase with

$ passgen passphrase

Provide a custom dictionary file for the passphrase

$ passgen passphrase -d /usr/share/dict/dict.txt

passgen Library

Full documentation for the library is found at GoDoc, including examples

Documentation

Overview

Package passgen allows for creating passwords and passphrases. Custom generators can be created to allow easy, full control of the types of passwords and passphrases generated

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAlphaLowerPassword

func GetAlphaLowerPassword(min, max int) (string, error)

Get a lowercase alphabetic password between min and max characters long

Example
p, err := GetAlphaLowerPassword(14, 20)
if err != nil {
	//handle error
}
fmt.Println(p)
Output:

func GetAlphaNumericPassword

func GetAlphaNumericPassword(min, max int) (string, error)

Get an alphanumeric password between min and max characters long

Example
p, err := GetAlphaNumericPassword(14, 20)
if err != nil {
	//handle error
}
fmt.Println(p)
Output:

func GetAlphaPassword

func GetAlphaPassword(min, max int) (string, error)

Get an alphabetic password between min and max characters long

func GetAlphaUpperPassword

func GetAlphaUpperPassword(min, max int) (string, error)

Get an uppercase alphabetic password between min and max characters long

Example
p, err := GetAlphaUpperPassword(14, 20)
if err != nil {
	//handle error
}
fmt.Println(p)
Output:

func GetNumericPassword

func GetNumericPassword(min, max int) (string, error)

Get a numeric password between min and max characters long

Example
p, err := GetNumericPassword(14, 20)
if err != nil {
	//handle error
}
fmt.Println(p)
Output:

func GetSecurePassword

func GetSecurePassword(min, max int) (string, error)

Get a secure password between min and max characters long

Example
p, err := GetSecurePassword(14, 20)
if err != nil {
	//handle error
}
fmt.Println(p)
Output:

func GetXKCDPassphrase

func GetXKCDPassphrase(numWords int) (string, error)

Quickly get a Passphrase according to XKCD example(http://xkcd.com/936/)

Example
p, err := GetXKCDPassphrase(4)
if err != nil {
	//handle error
}
fmt.Println(p)
Output:

Types

type PassphraseGenerator

type PassphraseGenerator struct {
	// Path of the Dictionary file to extract words from
	DictionaryFile string

	// Minimumum and Maximum word lengths of words that should be allowed in the passphrase
	MinWordLength, MaxWordLength int
	// contains filtered or unexported fields
}

Passphrase Generator is used to generate secure passphrases Can be reused to generate as many sequential passphrases as desired

Example
// Can use any PassphraseGenerator - provided or Custom
gen, err := GetXKCDPassphraseGenerator()
if err != nil {
	// Handle error
}
for i := 0; i < 5; i++ {
	p := gen.GeneratePassphrase(4)
	fmt.Println(p)
}
Output:

func GetXKCDPassphraseGenerator

func GetXKCDPassphraseGenerator() (*PassphraseGenerator, error)

Get a Passphrase Generator that exceeds the XKCD example (http://xkcd.com/936/). Creates a Passphrase Generator that chooses 4 words of between 4 to 10 characters long

func NewPassphraseGenerator

func NewPassphraseGenerator(dictFile string, min, max int) (*PassphraseGenerator, error)

Create a new Passphrase Generator. Use "internal" for the dictfile to use an internal list of words

Example
// This example will create a passphrase generator that will use 6 short words, 2 to 4 letter words, from the internal dictionary
gen, err := NewPassphraseGenerator("internal", 2, 4)
if err != nil {
	// Handle error
}
for i := 0; i < 5; i++ {
	p := gen.GeneratePassphrase(6)
	fmt.Println(p)
}
Output:

Example (DictionaryFile)
// This example will create a passphrase generator that will use a custom dictionary file for finding words
gen, err := NewPassphraseGenerator("path/to/dictionary", 4, 8)
if err != nil {
	// Handle error
}
for i := 0; i < 5; i++ {
	p := gen.GeneratePassphrase(4)
	fmt.Println(p)
}
Output:

func (*PassphraseGenerator) GeneratePassphrase

func (p *PassphraseGenerator) GeneratePassphrase(numWords int) string

Generate a Passphrase using the configuration options of the Passphrase Generator

type PasswordGenerator

type PasswordGenerator struct {
	// The ASCII Character to start pulling allowable password characters at
	CharStart byte
	// The number of Characters to be used for the password space
	CharLen int

	// Function to map a number to the ASCII character that should represent it
	Func func(i uint32) byte
	// contains filtered or unexported fields
}

Password Generator is used to generate passwords according to it's settings/properties. The generator can indefinitely be used to generate passwords.

Example
// Can use any PasswordGenerator - In this example, a SecurePasswordGenerator
gen := GetSecurePasswordGenerator()
for i := 0; i < 5; i++ {
	p, err := gen.GeneratePassword(14, 20)
	if err != nil {
		//handle error
	}
	fmt.Println(p)
}
Output:

func GetAlphaLowerPasswordGenerator

func GetAlphaLowerPasswordGenerator() *PasswordGenerator

Get a Password Generator that will only allow lower case alphabetic characters. (a-z) - 26 characters

func GetAlphaNumericPasswordGenerator

func GetAlphaNumericPasswordGenerator() *PasswordGenerator

Get a Password Generator that will only allow alphanumeric characters. (A-Za-z0-9) - 62 characters

func GetAlphaPasswordGenerator

func GetAlphaPasswordGenerator() *PasswordGenerator

Get a Password Generator that will only allow alphabetic characters. (A-Za-z) - 52 characters

func GetAlphaUpperPasswordGenerator

func GetAlphaUpperPasswordGenerator() *PasswordGenerator

Get a Password Generator that will only allow upper case alphabetic characters. (A-Z) - 26 characters

func GetNumericPasswordGenerator

func GetNumericPasswordGenerator() *PasswordGenerator

Get a Password Generator that will only allow numeric characters. (0-9) - 10 characters

func GetSecurePasswordGenerator

func GetSecurePasswordGenerator() *PasswordGenerator

Get a Password Generator that will allow ASCII x20-x7E - 95 characters

func NewPasswordGenerator

func NewPasswordGenerator(start byte, size int) *PasswordGenerator

Get a new Password Generator designed to start at the given starting character and use the given character space

Example
// Make a password generator that will only return passwords containing chars a-e
gen := NewPasswordGenerator('a', 5)

// Can now use the generator to create as many passwords as needed
for i := 0; i < 5; i++ {
	p, err := gen.GeneratePassword(14, 20)
	if err != nil {
		//handle error
	}
	fmt.Println(p)
}
Output:

Example (Custom)
// Make a password generator that will only return passwords containing chars of even numbers
gen := NewPasswordGenerator('0', 5)
gen.Func = func(i uint32) byte {
	diff := i * 2
	return gen.CharStart + byte(diff)
}

// Can now use the generator to create as many passwords as needed
for i := 0; i < 5; i++ {
	p, err := gen.GeneratePassword(14, 20)
	if err != nil {
		//handle error
	}
	fmt.Println(p)
}
Output:

func (*PasswordGenerator) GeneratePassword

func (p *PasswordGenerator) GeneratePassword(min, max int) (string, error)

Use the generator to create a password in between the given lengths

func (*PasswordGenerator) GetMaxLength

func (p *PasswordGenerator) GetMaxLength(n int) int

Get the maximum length in bytes that the generated password might need

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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