Began work on hashing api keys

This commit is contained in:
Torkel Ödegaard
2015-02-09 13:30:04 +01:00
parent c9f06e1da1
commit 5269422f7c
6 changed files with 33 additions and 29 deletions
+30
View File
@@ -0,0 +1,30 @@
package apikeygen
import (
"strconv"
"github.com/grafana/grafana/pkg/util"
)
type KeyGenResult struct {
HashedKey string
JsonKeyEncoded string
}
type ApiKeyJson struct {
Key string
AccountId int64
Name string
}
func GenerateNewKey(accountId int64, name string) KeyGenResult {
jsonKey := ApiKeyJson{}
jsonKey.AccountId = accountId
jsonKey.Name = name
jsonKey.Key = util.GetRandomString(32)
result := KeyGenResult{}
result.HashedKey = util.EncodePassword([]byte(jsonKey.Key), []byte(strconv.FormatInt(accountId, 10)))
}