Files
Mechiel Lukkien ced841b9b6 go fix
also switch to slices.ContainsFunc, also for the places where it becomes
a bit less easy to read. better not fight the changes...
2026-07-19 22:36:12 +02:00

25 lines
447 B
Go

package mox
import (
cryptorand "crypto/rand"
"strings"
)
func GeneratePassword() string {
chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*-_;:,<.>/"
var s strings.Builder
buf := make([]byte, 1)
for range 12 {
for {
cryptorand.Read(buf)
i := int(buf[0])
if i+len(chars) > 255 {
continue // Prevent bias.
}
s.WriteString(string(chars[i%len(chars)]))
break
}
}
return s.String()
}