MCPcopy
hub / github.com/tinode/chat / getPassword

Function getPassword

tinode-db/main.go:178–192  ·  view source on GitHub ↗

Generates password of length n

(n int)

Source from the content-addressed store, hash-verified

176
177// Generates password of length n
178func getPassword(n int) string {
179 const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/.+?=&"
180
181 rbuf := make([]byte, n)
182 if _, err := crand.Read(rbuf); err != nil {
183 log.Fatalln("Unable to generate password", err)
184 }
185
186 passwd := make([]byte, n)
187 for i, r := range rbuf {
188 passwd[i] = letters[int(r)%len(letters)]
189 }
190
191 return string(passwd)
192}
193
194func main() {
195 reset := flag.Bool("reset", false, "force database reset")

Callers 2

genDbFunction · 0.85
mainFunction · 0.85

Calls 1

ReadMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…