-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (66 loc) · 1.71 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// phrase - the passphrase generator
//go:generate go run generate.go
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/bjoernalbers/phrase/passphrase"
)
var (
version = "unset" // version gets set via build flags
homepage = "https://github.com/bjoernalbers/phrase"
)
func init() {
log.SetFlags(0)
log.SetPrefix(fmt.Sprintf("%s: ", filepath.Base(os.Args[0])))
flag.Usage = usage
}
func main() {
g := passphrase.Generator{}
flag.IntVar(&g.Words, "w", 4, "Words per passphrase")
flag.StringVar(&g.Separator, "s", " ", "Separator between words")
flag.BoolVar(&g.Capitalize, "C", false, "Capitalize all words")
flag.IntVar(&g.Digits, "d", 0, "Digits per passphrase")
flag.StringVar(&g.Language, "l", "en", "Language of passphrase: "+strings.Join(languages(), ", "))
filename := flag.String("f", "", "Diceware wordlist file")
passphrases := flag.Int("p", 1, "Passphrases")
flag.Parse()
var err error
if *filename != "" {
g.Wordlist, err = passphrase.ReadFile(*filename)
if err != nil {
log.Fatal(err)
}
}
for i := 0; i < *passphrases; i++ {
passphrase, err := g.Phrase()
if err != nil {
log.Fatal(err)
}
fmt.Println(passphrase)
}
}
func usage() {
header := fmt.Sprintf(`phrase - the passphrase generator (version %s)
Generate easy-to-remember passwords from random words.
Usage:
`, version)
footer := fmt.Sprintf(`
Homepage: %s
`, homepage)
fmt.Fprintf(flag.CommandLine.Output(), header)
flag.PrintDefaults()
fmt.Fprintf(flag.CommandLine.Output(), footer)
}
// languages returns the names of all build-in wordlists
func languages() []string {
list := []string{}
for language := range passphrase.Wordlists {
list = append(list, language)
}
return list
}