mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-06-10 06:54:30 +02:00
Introduce text IDs for everything (esp user), to avoid security and accounting issues
This commit is contained in:
parent
88abd8872d
commit
9c082a8331
13 changed files with 160 additions and 108 deletions
util
|
@ -107,13 +107,18 @@ func LastString(s []string, def string) string {
|
|||
|
||||
// RandomString returns a random string with a given length
|
||||
func RandomString(length int) string {
|
||||
return RandomStringPrefix("", length)
|
||||
}
|
||||
|
||||
// RandomStringPrefix returns a random string with a given length, with a prefix
|
||||
func RandomStringPrefix(prefix string, length int) string {
|
||||
randomMutex.Lock() // Who would have thought that random.Intn() is not thread-safe?!
|
||||
defer randomMutex.Unlock()
|
||||
b := make([]byte, length)
|
||||
b := make([]byte, length-len(prefix))
|
||||
for i := range b {
|
||||
b[i] = randomStringCharset[random.Intn(len(randomStringCharset))]
|
||||
}
|
||||
return string(b)
|
||||
return prefix + string(b)
|
||||
}
|
||||
|
||||
// ValidRandomString returns true if the given string matches the format created by RandomString
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue