more
This commit is contained in:
21
util/rand.go
21
util/rand.go
@@ -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:]
|
||||
}
|
||||
Reference in New Issue
Block a user