mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
42ca90a40c
For security reason I replaced math/rand to crypto/rand in places where it is critical. I didn't do this in tests.
24 lines
384 B
Go
24 lines
384 B
Go
package random
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
)
|
|
|
|
const (
|
|
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
)
|
|
|
|
func String(strlen int) string {
|
|
result := make([]byte, strlen)
|
|
charLen := big.NewInt(int64(len(chars)))
|
|
for i := range result {
|
|
r, err := rand.Int(rand.Reader, charLen)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
result[i] = chars[r.Int64()]
|
|
}
|
|
return string(result)
|
|
}
|