-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (31 loc) · 933 Bytes
/
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
package main
import (
"crypto/rand"
"encoding/base64"
"flag"
"fmt"
"log"
)
var encoder *base64.Encoding
var punc1 = flag.String("p", "?", "first potential punctuation in password, default = ?")
var punc2 = flag.String("P", "!", "second potential punctuation in password, default = !")
func init() {
flag.Parse()
if len(*punc1) != 1 || len(*punc2) != 1 {
log.Fatalln("only single character for potential punctuation")
}
encoder = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + *punc1 + *punc2)
}
var length = flag.Int("l", 12, "length of generated password, default = 12")
func main() {
var bytelength int = (*length * 3) / 4
for bytelength*4 < *length*3 {
bytelength++
}
buffer := make([]byte, bytelength)
_, err := rand.Read(buffer)
if err != nil {
log.Fatalf("unable to acquire random bytes: %v\n", err)
}
fmt.Println(encoder.EncodeToString(buffer)[:*length])
}