forked from forgejo/forgejo
Convert captcha, cache, csrf as middlewares
This commit is contained in:
parent
3428baa3b5
commit
7bbf644dd5
17 changed files with 46 additions and 1122 deletions
|
@ -103,7 +103,6 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
|
|||
"ActionContent2Commits": ActionContent2Commits,
|
||||
"Oauth2Icon": Oauth2Icon,
|
||||
"Oauth2Name": Oauth2Name,
|
||||
"CreateCaptcha": func() string { return "" },
|
||||
}
|
||||
|
||||
type Actioner interface {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue