mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-19 07:04:10 +09:00
26 lines
586 B
Go
26 lines
586 B
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
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
|
|
}
|