lessmore/node/helpers.go
2018-11-05 18:24:46 +03:00

31 lines
532 B
Go

package node
import (
"log"
"time"
mrand "math/rand"
"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
}