mirror of
https://github.com/grafana/grafana.git
synced 2026-08-14 07:04:57 -05:00
Began work on hashing api keys
This commit is contained in:
@@ -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)))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user