19 lines
331 B
Go
19 lines
331 B
Go
package handlers
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// GenerateKey produces a license key in the format XXXX-XXXX-XXXX-XXXX
|
|
func GenerateKey() string {
|
|
b := make([]byte, 8)
|
|
rand.Read(b)
|
|
hex := fmt.Sprintf("%X", b)
|
|
parts := []string{
|
|
hex[0:4], hex[4:8], hex[8:12], hex[12:16],
|
|
}
|
|
return strings.Join(parts, "-")
|
|
}
|