mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2025-01-07 09:50:18 +01:00
Generate secure token using crypto rand
This commit is contained in:
parent
54b4f1aa86
commit
ca5c89f130
1 changed files with 8 additions and 3 deletions
|
@ -25,7 +25,9 @@ THE SOFTWARE.
|
|||
package server
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"crypto/rand"
|
||||
"log"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -37,8 +39,11 @@ const (
|
|||
func token(length int) string {
|
||||
result := ""
|
||||
for i := 0; i < length; i++ {
|
||||
x := rand.Intn(len(SYMBOLS) - 1)
|
||||
result = string(SYMBOLS[x]) + result
|
||||
x, err := rand.Int(rand.Reader, big.NewInt(int64(len(SYMBOLS))))
|
||||
if err != nil {
|
||||
log.Fatal("Failed to generate token")
|
||||
}
|
||||
result = string(SYMBOLS[x.Int64()]) + result
|
||||
}
|
||||
|
||||
return result
|
||||
|
|
Loading…
Reference in a new issue