-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
68 lines (56 loc) · 1.69 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
package main
import (
"flag"
"fmt"
"github.com/ChristianSiegert/go-password-generator/generator"
)
var (
customCharacters = flag.String("custom", "", "Custom set of characters to use")
passwordCount = flag.Int("count", 10, "Number of passwords to generate")
passwordLength = flag.Int("length", 20, "Length of passwords")
useLowerCaseCharacters = flag.Bool("lower", false, "Use lower-case characters a-z")
useNumbers = flag.Bool("numbers", false, "Use numbers 0-9")
useSpecialCharacters = flag.Bool("special", false, "Use special characters !§$%&=?,.-;:_")
useUpperCaseCharacters = flag.Bool("upper", false, "Use upper-case characters A-Z")
verbose = flag.Bool("verbose", false, "Display additional information")
)
func main() {
flag.Parse()
generator, error := generator.NewGenerator(
*useLowerCaseCharacters,
*useUpperCaseCharacters,
*useNumbers,
*useSpecialCharacters,
*customCharacters,
*passwordLength,
)
if error != nil {
fmt.Println("Error:", error)
return
}
if *verbose {
fmt.Println(additionalInformation(generator))
}
for i := 0; i < *passwordCount; i++ {
password, error := generator.Password(*passwordLength)
if error != nil {
fmt.Println("Error:", error)
continue
}
fmt.Println(password)
}
}
func additionalInformation(generator *generator.Generator) string {
passwordCountInWords := ""
if *passwordCount == 1 {
passwordCountInWords = "1 password"
} else {
passwordCountInWords = fmt.Sprintf("%d passwords", *passwordCount)
}
return fmt.Sprintf(
"Generating %s with a length of %d from the following characters: %s",
passwordCountInWords,
*passwordLength,
generator.Characters(),
)
}