Move to Donetick Org, first commit
This commit is contained in:
commit
c13dd9addb
42 changed files with 7463 additions and 0 deletions
28
internal/utils/key_generator.go
Normal file
28
internal/utils/key_generator.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
crand "crypto/rand"
|
||||
|
||||
"donetick.com/core/logging"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GenerateInviteCode(c *gin.Context) string {
|
||||
logger := logging.FromContext(c)
|
||||
// Define the length of the token (in bytes). For example, 32 bytes will result in a 44-character base64-encoded token.
|
||||
tokenLength := 12
|
||||
|
||||
// Generate a random byte slice.
|
||||
tokenBytes := make([]byte, tokenLength)
|
||||
_, err := crand.Read(tokenBytes)
|
||||
if err != nil {
|
||||
logger.Errorw("utility.GenerateEmailResetToken failed to generate random bytes", "err", err)
|
||||
}
|
||||
|
||||
// Encode the byte slice to a base64 string.
|
||||
token := base64.URLEncoding.EncodeToString(tokenBytes)
|
||||
|
||||
return token
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue