mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-28 09:25:37 +02:00
Newly created access tokens are now lowercase only
This commit is contained in:
parent
ae3e8a0094
commit
e96e35b40b
4 changed files with 27 additions and 3 deletions
util
14
util/util.go
14
util/util.go
|
@ -23,7 +23,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
randomStringCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
randomStringCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
randomStringLowerCaseCharset = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -112,11 +113,20 @@ func RandomString(length int) string {
|
|||
|
||||
// RandomStringPrefix returns a random string with a given length, with a prefix
|
||||
func RandomStringPrefix(prefix string, length int) string {
|
||||
return randomStringPrefixWithCharset(prefix, length, randomStringCharset)
|
||||
}
|
||||
|
||||
// RandomLowerStringPrefix returns a random lowercase-only string with a given length, with a prefix
|
||||
func RandomLowerStringPrefix(prefix string, length int) string {
|
||||
return randomStringPrefixWithCharset(prefix, length, randomStringLowerCaseCharset)
|
||||
}
|
||||
|
||||
func randomStringPrefixWithCharset(prefix string, length int, charset string) string {
|
||||
randomMutex.Lock() // Who would have thought that random.Intn() is not thread-safe?!
|
||||
defer randomMutex.Unlock()
|
||||
b := make([]byte, length-len(prefix))
|
||||
for i := range b {
|
||||
b[i] = randomStringCharset[random.Intn(len(randomStringCharset))]
|
||||
b[i] = charset[random.Intn(len(charset))]
|
||||
}
|
||||
return prefix + string(b)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue