From 7bbf644dd5eaca77c3e8df57419180486bda0fc2 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 31 Jul 2014 17:25:34 -0400 Subject: Convert captcha, cache, csrf as middlewares --- modules/base/tool.go | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'modules/base/tool.go') diff --git a/modules/base/tool.go b/modules/base/tool.go index 830c37f6..a2a155d6 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -13,7 +13,6 @@ import ( "fmt" "hash" "math" - r "math/rand" "strings" "time" @@ -45,33 +44,6 @@ func GetRandomString(n int, alphabets ...byte) string { return string(bytes) } -// RandomCreateBytes generate random []byte by specify chars. -func RandomCreateBytes(n int, alphabets ...byte) []byte { - const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - var bytes = make([]byte, n) - var randby bool - if num, err := rand.Read(bytes); num != n || err != nil { - r.Seed(time.Now().UnixNano()) - randby = true - } - for i, b := range bytes { - if len(alphabets) == 0 { - if randby { - bytes[i] = alphanum[r.Intn(len(alphanum))] - } else { - bytes[i] = alphanum[b%byte(len(alphanum))] - } - } else { - if randby { - bytes[i] = alphabets[r.Intn(len(alphabets))] - } else { - bytes[i] = alphabets[b%byte(len(alphabets))] - } - } - } - return bytes -} - // http://code.google.com/p/go/source/browse/pbkdf2/pbkdf2.go?repo=crypto func PBKDF2(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte { prf := hmac.New(h, password) -- cgit v1.2.3