about summary refs log tree commit diff
path: root/src/access.go
blob: 6de2c05015bf8ee4e5e05cd47d6fa0a6fdfd4a33 (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
26
package main

import (
	"math/rand"
	"strings"
	"time"
)

func newAccessCode(length int) string {
	// seed the random numbergenerator
	rand.Seed(time.Now().UnixNano())

	// define the alphabet
	chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
		"abcdefghijklmnopqrstuvwxyz" +
		"0123456789")

	// build the accesscode
	var b strings.Builder
	for i := 0; i < length; i++ {
		b.WriteRune(chars[rand.Intn(len(chars))])
	}
	str := b.String()

	return str
}