summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorslene <vslene@gmail.com>2014-03-23 01:44:02 +0800
committerslene <vslene@gmail.com>2014-03-23 01:44:02 +0800
commit076fc98d981aea3533eea363ca1c7e43f77b9802 (patch)
tree596d754de0d53a7e0794dcd61122ddb85298a0e1 /modules/base
parent01e781dedb3c6d48349516de0eee5cea41c077e1 (diff)
downloadgitea-076fc98d981aea3533eea363ca1c7e43f77b9802.tar.gz
gitea-076fc98d981aea3533eea363ca1c7e43f77b9802.zip
add csrf check
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 8fabb8c531..a2aeebf1b8 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -25,13 +25,17 @@ func EncodeMd5(str string) string {
return hex.EncodeToString(m.Sum(nil))
}
-// Random generate string
-func GetRandomString(n int) string {
+// GetRandomString generate random string by specify chars.
+func GetRandomString(n int, alphabets ...byte) string {
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var bytes = make([]byte, n)
rand.Read(bytes)
for i, b := range bytes {
- bytes[i] = alphanum[b%byte(len(alphanum))]
+ if len(alphabets) == 0 {
+ bytes[i] = alphanum[b%byte(len(alphanum))]
+ } else {
+ bytes[i] = alphabets[b%byte(len(alphabets))]
+ }
}
return string(bytes)
}