Changed SessionID format.

Pusher libs are validating the sessionID format. So I need to conform
with its format.
This commit is contained in:
claudemiro
2015-05-17 09:25:57 -03:00
parent 7b578c4fb4
commit 485bc01abe
3 changed files with 28 additions and 10 deletions
+7 -9
View File
@@ -6,10 +6,11 @@ package utils
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"encoding/base32"
"encoding/hex"
"fmt"
"math/rand"
"time"
)
// HashMAC Calculates the MAC signing with the given key and returns the hexadecimal encoded Result
@@ -22,12 +23,9 @@ func HashMAC(message, key []byte) string {
}
// Generate a new random Hash
func RandomHash() string {
b := make([]byte, 25)
func GenerateSessionID() string {
MAX := 999999999
rand.Seed(time.Now().Unix())
if _, err := rand.Read(b); err != nil {
panic("websockets: Could not generate a random session ID")
}
return base32.StdEncoding.EncodeToString(b)
return fmt.Sprintf("%d.%d", rand.Intn(MAX), rand.Intn(MAX))
}