diff options
Diffstat (limited to 'app/models/auth_session_util.go')
-rw-r--r-- | app/models/auth_session_util.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/auth_session_util.go b/app/models/auth_session_util.go new file mode 100644 index 0000000..1f1474a --- /dev/null +++ b/app/models/auth_session_util.go | |||
@@ -0,0 +1,25 @@ | |||
1 | package models | ||
2 | |||
3 | import ( | ||
4 | "crypto/rand" | ||
5 | "encoding/base32" | ||
6 | "encoding/base64" | ||
7 | "fmt" | ||
8 | ) | ||
9 | |||
10 | func createDeviceCode() string { | ||
11 | buf := make([]byte, 32) | ||
12 | if _, err := rand.Read(buf); err != nil { | ||
13 | panic(err) | ||
14 | } | ||
15 | return base64.URLEncoding.EncodeToString(buf) | ||
16 | } | ||
17 | |||
18 | func createUserCode() string { | ||
19 | buf := make([]byte, 32) | ||
20 | if _, err := rand.Read(buf); err != nil { | ||
21 | panic(err) | ||
22 | } | ||
23 | userCodeRaw := base32.StdEncoding.EncodeToString(buf) | ||
24 | return fmt.Sprintf("%s-%s", userCodeRaw[0:4], userCodeRaw[5:9]) | ||
25 | } | ||