mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
also switch to slices.ContainsFunc, also for the places where it becomes a bit less easy to read. better not fight the changes...
25 lines
447 B
Go
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()
|
|
}
|