gowiki/pkg/db/helper.go
2018-09-19 00:10:16 +02:00

50 lines
683 B
Go

// Copyright (C) 2018 Marius Schellenberger
package db
import (
"crypto/sha256"
"time"
)
var reservedUsers = []string{
"all",
"blacklist",
"login",
"logout",
"new",
"search",
"user",
"view",
"wiki",
}
func reservedUser(username string) bool {
for _, v := range reservedUsers {
if username == v {
return true
}
}
return false
}
func validatePassword(pw string) (b []byte) {
b = []byte(pw)
if len(pw) <= 56 {
return
}
hash := sha256.New()
hash.Write(b)
b = hash.Sum(nil)
return
}
const timeFmt = "2006-01-02 15:04:05"
func now() string {
return time.Now().Format(timeFmt)
}
func created(username string) string {
return username + " " + now()
}