mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 18:10:54 +00:00
fix #249
This commit is contained in:
parent
6ea8dd5999
commit
13180c5a17
@ -217,24 +217,23 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque
|
|||||||
//remote_addr cruunixnano randdata
|
//remote_addr cruunixnano randdata
|
||||||
|
|
||||||
func (manager *Manager) sessionId(r *http.Request) (sid string) {
|
func (manager *Manager) sessionId(r *http.Request) (sid string) {
|
||||||
b := make([]byte, 24)
|
bs := make([]byte, 24)
|
||||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
if _, err := io.ReadFull(rand.Reader, bs); err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
bs := base64.URLEncoding.EncodeToString(b)
|
|
||||||
sig := fmt.Sprintf("%s%d%s", r.RemoteAddr, time.Now().UnixNano(), bs)
|
sig := fmt.Sprintf("%s%d%s", r.RemoteAddr, time.Now().UnixNano(), bs)
|
||||||
if manager.hashfunc == "md5" {
|
if manager.hashfunc == "md5" {
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
h.Write([]byte(bs))
|
h.Write([]byte(sig))
|
||||||
sid = fmt.Sprintf("%s", hex.EncodeToString(h.Sum(nil)))
|
sid = hex.EncodeToString(h.Sum(nil))
|
||||||
} else if manager.hashfunc == "sha1" {
|
} else if manager.hashfunc == "sha1" {
|
||||||
h := hmac.New(sha1.New, []byte(manager.hashkey))
|
h := hmac.New(sha1.New, []byte(manager.hashkey))
|
||||||
fmt.Fprintf(h, "%s", sig)
|
fmt.Fprintf(h, "%s", sig)
|
||||||
sid = fmt.Sprintf("%s", hex.EncodeToString(h.Sum(nil)))
|
sid = hex.EncodeToString(h.Sum(nil))
|
||||||
} else {
|
} else {
|
||||||
h := hmac.New(sha1.New, []byte(manager.hashkey))
|
h := hmac.New(sha1.New, []byte(manager.hashkey))
|
||||||
fmt.Fprintf(h, "%s", sig)
|
fmt.Fprintf(h, "%s", sig)
|
||||||
sid = fmt.Sprintf("%s", hex.EncodeToString(h.Sum(nil)))
|
sid = hex.EncodeToString(h.Sum(nil))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user