lessmore/node/helpers.go

55 lines
1.1 KiB
Go
Raw Normal View History

2018-11-05 18:24:46 +03:00
package node
import (
"time"
mrand "math/rand"
2018-11-06 08:41:04 +03:00
"strings"
log "github.com/Sirupsen/logrus"
2018-11-05 18:24:46 +03:00
"golang.org/x/crypto/bcrypt"
)
func hashAndSalt(authString []byte) string {
hash, err := bcrypt.GenerateFromPassword(authString, bcrypt.MinCost)
if err != nil {
log.Fatal(err.Error())
}
return string(hash)
}
// genAuthString random auth string
func genAuthString() []byte {
authString := make([]byte, AUTH_STRING_LENGTH)
mrand.Seed(time.Now().UnixNano())
for i := range authString {
authString[i] = LETTERS[mrand.Intn(len(LETTERS))]
}
return authString
}
2018-11-06 08:41:04 +03:00
// parsePointBody without regexp
// it dirty hack mades because *http.Request.Form not parsed it
func parsePointBody(content string) (string, string) {
var pauth, tmsg string
log.Debug("Body parser: ", content)
if strings.Contains(content, "&") {
log.Debug("Found &")
for _, v := range strings.Split(content, "&") {
if strings.Contains(v, "pauth") {
log.Debug("Found pauth")
pauth = strings.Split(v, "pauth=")[1]
}
if strings.Contains(v, "tmsg") {
log.Debug("Found tmsg")
tmsg = strings.Split(v, "tmsg=")[1]
}
}
}
return pauth, tmsg
}