mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-01 14:56:30 +00:00
27 lines
658 B
Go
27 lines
658 B
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package bots
|
|
|
|
import (
|
|
"encoding/hex"
|
|
|
|
auth_model "code.gitea.io/gitea/models/auth"
|
|
"code.gitea.io/gitea/modules/util"
|
|
)
|
|
|
|
func generateSaltedToken() (string, string, string, string, error) {
|
|
salt, err := util.CryptoRandomString(10)
|
|
if err != nil {
|
|
return "", "", "", "", err
|
|
}
|
|
buf, err := util.CryptoRandomBytes(20)
|
|
if err != nil {
|
|
return "", "", "", "", err
|
|
}
|
|
token := hex.EncodeToString(buf)
|
|
hash := auth_model.HashToken(token, salt)
|
|
return token, salt, hash, token[:8], nil
|
|
}
|