1package mox
2
3import (
4 cryptorand "crypto/rand"
5 "strings"
6)
7
8func GeneratePassword() string {
9 chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*-_;:,<.>/"
10 var s strings.Builder
11 buf := make([]byte, 1)
12 for range 12 {
13 for {
14 cryptorand.Read(buf)
15 i := int(buf[0])
16 if i+len(chars) > 255 {
17 continue // Prevent bias.
18 }
19 s.WriteString(string(chars[i%len(chars)]))
20 break
21 }
22 }
23 return s.String()
24}
25