Allows creating new remote clusters without providing a password (#27864)

* Allows creating new remote clusters without providing a password

If the endpoint receives a request with no password, it will generate
one internally and return it in the response, so the frotend can show
it to the user.

* Use a random string instead of a UUID for the generated password

* Update function name to avoid CString reference and adds assertion

* Update server/channels/utils/textgeneration.go

Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com>

* Extends the charset

---------

Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com>
Этот коммит содержится в:
Miguel de la Cruz
2024-08-08 12:18:21 +02:00
коммит произвёл GitHub
родитель 06d8c857ea
Коммит eec9a4742a
5 изменённых файлов: 69 добавлений и 20 удалений

Просмотреть файл

@@ -4,7 +4,9 @@
package utils
import (
"math/rand"
crand "crypto/rand"
"math/big"
mrand "math/rand"
"strings"
)
@@ -468,11 +470,23 @@ Up to and hey without pill that this squid alas brusque on inventoried and sprea
func RandString(l int, charset string) string {
ret := make([]byte, l)
for i := 0; i < l; i++ {
ret[i] = charset[rand.Intn(len(charset))]
ret[i] = charset[mrand.Intn(len(charset))]
}
return string(ret)
}
func SecureRandString(n int) string {
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*0123456789"
var str strings.Builder
for i := 0; i < n; i++ {
num, _ := crand.Int(crand.Reader, big.NewInt(int64(len(charset))))
str.WriteString(string(charset[num.Int64()]))
}
return str.String()
}
// func RandomEmail(length Range, charset string) string {
// emaillen := RandIntFromRange(length)
// username := RandString(emaillen, charset)
@@ -517,7 +531,7 @@ func RandomText(length Range, hashtags Range, mentions Range, users []string) st
// Shuffle the words
for i := range words {
j := rand.Intn(i + 1)
j := mrand.Intn(i + 1)
words[i], words[j] = words[j], words[i]
}