13180c5a by astaxie

fix #249

1 parent 6ea8dd59
...@@ -217,24 +217,23 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque ...@@ -217,24 +217,23 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque
217 //remote_addr cruunixnano randdata 217 //remote_addr cruunixnano randdata
218 218
219 func (manager *Manager) sessionId(r *http.Request) (sid string) { 219 func (manager *Manager) sessionId(r *http.Request) (sid string) {
220 b := make([]byte, 24) 220 bs := make([]byte, 24)
221 if _, err := io.ReadFull(rand.Reader, b); err != nil { 221 if _, err := io.ReadFull(rand.Reader, bs); err != nil {
222 return "" 222 return ""
223 } 223 }
224 bs := base64.URLEncoding.EncodeToString(b)
225 sig := fmt.Sprintf("%s%d%s", r.RemoteAddr, time.Now().UnixNano(), bs) 224 sig := fmt.Sprintf("%s%d%s", r.RemoteAddr, time.Now().UnixNano(), bs)
226 if manager.hashfunc == "md5" { 225 if manager.hashfunc == "md5" {
227 h := md5.New() 226 h := md5.New()
228 h.Write([]byte(bs)) 227 h.Write([]byte(sig))
229 sid = fmt.Sprintf("%s", hex.EncodeToString(h.Sum(nil))) 228 sid = hex.EncodeToString(h.Sum(nil))
230 } else if manager.hashfunc == "sha1" { 229 } else if manager.hashfunc == "sha1" {
231 h := hmac.New(sha1.New, []byte(manager.hashkey)) 230 h := hmac.New(sha1.New, []byte(manager.hashkey))
232 fmt.Fprintf(h, "%s", sig) 231 fmt.Fprintf(h, "%s", sig)
233 sid = fmt.Sprintf("%s", hex.EncodeToString(h.Sum(nil))) 232 sid = hex.EncodeToString(h.Sum(nil))
234 } else { 233 } else {
235 h := hmac.New(sha1.New, []byte(manager.hashkey)) 234 h := hmac.New(sha1.New, []byte(manager.hashkey))
236 fmt.Fprintf(h, "%s", sig) 235 fmt.Fprintf(h, "%s", sig)
237 sid = fmt.Sprintf("%s", hex.EncodeToString(h.Sum(nil))) 236 sid = hex.EncodeToString(h.Sum(nil))
238 } 237 }
239 return 238 return
240 } 239 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!