summaryrefslogtreecommitdiff
path: root/shrine/utils/crypto/refs.go
blob: e0380042b866e8f81247592ca62014691de8824b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package crypto

import (
	"crypto/rand"
	"time"
)

const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"

func randomString(length int) string {
	bytes := make([]byte, length)
	rand.Read(bytes)
	for i := range bytes {
		bytes[i] = alphabet[bytes[i]%byte(len(alphabet))]
	}
	return string(bytes)
}

func SystemRef() string {
	return time.Now().Format("020106") + randomString(8)
}

func Ref() string {
	return randomString(12)
}