Files
postmoogle/vendor/gitlab.com/etke.cc/go/secgen/password.go
2022-11-16 12:08:51 +02:00

23 lines
450 B
Go

package secgen
import (
"crypto/rand"
"math/big"
"strings"
)
const charset = "abcdedfghijklmnopqrstABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // a-z A-Z 0-9
var charsetlen = big.NewInt(57)
// Password generates secure password
func Password(length int) string {
var password strings.Builder
for i := 0; i < length; i++ {
index, _ := rand.Int(rand.Reader, charsetlen)
password.WriteByte(charset[index.Int64()])
}
return password.String()
}