mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-04 11:19:39 -06:00
21 lines
437 B
Go
21 lines
437 B
Go
package generators
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
)
|
|
|
|
func GenerateRandomPassword(length int) (string, error) {
|
|
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-=+!@#$%^&*."
|
|
ret := make([]byte, length)
|
|
for i := 0; i < length; i++ {
|
|
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(chars))))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
ret[i] = chars[num.Int64()]
|
|
}
|
|
|
|
return string(ret), nil
|
|
}
|