mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2025-01-08 10:10:19 +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
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"crypto/rand"
|
||||||
|
"log"
|
||||||
|
"math/big"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -37,8 +39,11 @@ const (
|
||||||
func token(length int) string {
|
func token(length int) string {
|
||||||
result := ""
|
result := ""
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
x := rand.Intn(len(SYMBOLS) - 1)
|
x, err := rand.Int(rand.Reader, big.NewInt(int64(len(SYMBOLS))))
|
||||||
result = string(SYMBOLS[x]) + result
|
if err != nil {
|
||||||
|
log.Fatal("Failed to generate token")
|
||||||
|
}
|
||||||
|
result = string(SYMBOLS[x.Int64()]) + result
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue