This commit is contained in:
2022-12-09 23:26:38 -06:00
parent 8df6231b71
commit d8a6c8acd1
15 changed files with 643 additions and 56 deletions

View File

@@ -4,9 +4,12 @@ import (
"encoding/hex"
"math/rand"
"time"
"github.com/bwmarrin/snowflake"
)
var passwordChars = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=_+!@#$%^&*()[]{}|;:,.<>/?")
// var passwordChars = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=_+!@#$%^&*()[]{}|;:,.<>/?")
var passwordChars = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=_+!@#$%^&*?")
func GeneratePassword(length int) string {
rand.Seed(time.Now().UnixNano())
@@ -26,4 +29,20 @@ func GenerateToken() string {
return ""
}
return hex.EncodeToString(b)
}
var snowflakeNodeIndex int64 = 0
func GenerateID() string {
node, err := snowflake.NewNode(snowflakeNodeIndex)
if err != nil {
panic(err)
}
return node.Generate().String()
}
func GetEnd(token string) string {
if len(token) < 8 {
return ""
}
return token[len(token)-8:]
}