mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-08-07 05:14:57 -04:00
add password generator
Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
1 parent
d106c87c51
commit
c5d0791f53
3 files changed
+46
No files matched your search
@@ -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")
|
||||||
|
}
|
||||||
@@ -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() {})
|
||||||
|
})
|
||||||
@@ -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