From 1de947cedc2c452343b159abbb8460768b5d0960 Mon Sep 17 00:00:00 2001 From: claudemiro Date: Mon, 18 Jan 2016 00:37:55 -0200 Subject: [PATCH] The random Seed should be executed only once. If two users connect to the system in the same second both would receive the same id. This fix this error. --- ipe/ipe.go | 3 +++ utils/utils.go | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ipe/ipe.go b/ipe/ipe.go index a89194e..4e5db24 100644 --- a/ipe/ipe.go +++ b/ipe/ipe.go @@ -8,6 +8,8 @@ import ( "encoding/json" "io/ioutil" "net/http" + "math/rand" + "time" ) // Conf holds the global configuration state @@ -15,6 +17,7 @@ var conf configFile // Start Parse the configuration file and starts the ipe server func Start(configfile string) error { + rand.Seed(time.Now().Unix()) file, err := ioutil.ReadFile(configfile) if err != nil { diff --git a/utils/utils.go b/utils/utils.go index 7b7ab9c..4dffd74 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -11,7 +11,6 @@ import ( "fmt" "math/rand" "regexp" - "time" ) // HashMAC Calculates the MAC signing with the given key and returns the hexadecimal encoded Result @@ -26,7 +25,6 @@ func HashMAC(message, key []byte) string { // GenerateSessionID Generate a new random Hash func GenerateSessionID() string { MAX := 999999999 - rand.Seed(time.Now().Unix()) return fmt.Sprintf("%d.%d", rand.Intn(MAX), rand.Intn(MAX)) }