mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-18 15:24:25 +02:00
* lint: gocritic configuration * lint: octal literals * lint: gocritic (filepath.Join) * ling: gocritic (badRegexp, regexpSimplify) * lint: gocritic (preferStringWriter) * lint: gocritic (emtpyStringTest) * filepath.Clean(a+b) -> filepath.Join(a, b) * gofumpt
32 lines
634 B
Go
32 lines
634 B
Go
package idgen
|
|
|
|
import (
|
|
saferand "crypto/rand"
|
|
"math/big"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
const PasswordLength = 64
|
|
|
|
func GeneratePassword(length int) string {
|
|
upper := "ABCDEFGHIJKLMNOPQRSTUVWXY"
|
|
lower := "abcdefghijklmnopqrstuvwxyz"
|
|
digits := "0123456789"
|
|
|
|
charset := upper + lower + digits
|
|
charsetLength := len(charset)
|
|
|
|
buf := make([]byte, length)
|
|
|
|
for i := range length {
|
|
rInt, err := saferand.Int(saferand.Reader, big.NewInt(int64(charsetLength)))
|
|
if err != nil {
|
|
log.Fatalf("failed getting data from prng for password generation : %s", err)
|
|
}
|
|
|
|
buf[i] = charset[rInt.Int64()]
|
|
}
|
|
|
|
return string(buf)
|
|
}
|