mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-20 04:29:24 -06:00
add password generator
Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
13
ocis-pkg/generators/generators_suite_test.go
Normal file
13
ocis-pkg/generators/generators_suite_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package generators_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestGenerators(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Generators Suite")
|
||||
}
|
||||
13
ocis-pkg/generators/generators_test.go
Normal file
13
ocis-pkg/generators/generators_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package generators_test
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
. "github.com/owncloud/ocis/ocis-pkg/generators"
|
||||
)
|
||||
|
||||
var _ = Describe("Generators", func() {
|
||||
It("Returns an error ", func() {})
|
||||
PIt("Returns expected passwords", func() {})
|
||||
})
|
||||
20
ocis-pkg/generators/password.go
Normal file
20
ocis-pkg/generators/password.go
Normal file
@@ -0,0 +1,20 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user