diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-07-31 17:25:34 -0400 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-07-31 17:25:34 -0400 |
commit | 7bbf644dd5eaca77c3e8df57419180486bda0fc2 (patch) | |
tree | 84033fb9507c4657d74b85dccd5f16595f8517a8 /modules/base/tool.go | |
parent | 3428baa3b57b39f2e010254bffede93e7d3cdf37 (diff) |
Convert captcha, cache, csrf as middlewares
Diffstat (limited to 'modules/base/tool.go')
-rw-r--r-- | modules/base/tool.go | 28 |
1 files changed, 0 insertions, 28 deletions
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) |