hello world

This commit is contained in:
2022-12-09 10:59:15 -06:00
commit 8ae527683b
13 changed files with 552 additions and 0 deletions

29
util/rand.go Normal file
View File

@@ -0,0 +1,29 @@
package util
import (
"encoding/hex"
"math/rand"
"time"
)
var passwordChars = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=_+!@#$%^&*()[]{}|;:,.<>/?")
func GeneratePassword(length int) string {
rand.Seed(time.Now().UnixNano())
b := make([]rune, length)
for i := range b {
b[i] = passwordChars[rand.Intn(len(passwordChars))]
}
code := string(b)
return code
}
func GenerateToken() string {
rand.Seed(time.Now().UnixNano())
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
return ""
}
return hex.EncodeToString(b)
}