-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (61 loc) · 1.5 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
package main
import (
"fmt"
"github.com/jedib0t/go-passwords/charset"
"github.com/jedib0t/go-passwords/odometer"
"github.com/jedib0t/go-passwords/passphrase"
"github.com/jedib0t/go-passwords/passphrase/dictionaries"
"github.com/jedib0t/go-passwords/password"
)
func main() {
fmt.Println("Passphrases:")
demoPassphraseGenerator()
fmt.Println()
fmt.Println("Passwords:")
demoPasswordGenerator()
fmt.Println()
fmt.Println("Odometer:")
demoOdometer()
fmt.Println()
}
func demoPassphraseGenerator() {
g, err := passphrase.NewGenerator(
passphrase.WithCapitalizedWords(true),
passphrase.WithDictionary(dictionaries.English()),
passphrase.WithNumWords(3),
passphrase.WithNumber(true),
passphrase.WithSeparator("-"),
passphrase.WithWordLength(4, 6),
)
if err != nil {
panic(err.Error())
}
for idx := 1; idx <= 10; idx++ {
fmt.Printf("Passphrase #%3d: %#v\n", idx, g.Generate())
}
}
func demoPasswordGenerator() {
g, err := password.NewGenerator(
password.WithCharset(charset.AllChars.WithoutAmbiguity().WithoutDuplicates()),
password.WithLength(12),
password.WithMinLowerCase(5),
password.WithMinUpperCase(2),
password.WithNumSymbols(1, 1),
)
if err != nil {
panic(err.Error())
}
for idx := 1; idx <= 10; idx++ {
fmt.Printf("Password #%3d: %#v\n", idx, g.Generate())
}
}
func demoOdometer() {
o := odometer.New(charset.AlphabetsUpper, 8)
for idx := 1; idx <= 10; idx++ {
fmt.Printf("Password #%3d: %#v\n", idx, o.String())
if o.AtEnd() {
break
}
o.Increment()
}
}