5be7f7f04b
- Qt 6 desktop client with day/month/year views, AI scheduling, and TOML settings\n- Go sync server with SQLite change stream, WebSocket notifications, and Docker deployment\n- Client outbox/LWW sync, offline retry, and dual-client integration tests\n- Linux fcitx5 setup, validation reports, and Windows MinGW preset
24 lines
545 B
Go
24 lines
545 B
Go
package auth
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/sha256"
|
|
"encoding/base64"
|
|
"encoding/hex"
|
|
)
|
|
|
|
// GenerateToken returns a URL-safe random token and its storage hash.
|
|
func GenerateToken(pepper string) (string, string, error) {
|
|
buf := make([]byte, 32)
|
|
if _, err := rand.Read(buf); err != nil {
|
|
return "", "", err
|
|
}
|
|
token := base64.RawURLEncoding.EncodeToString(buf)
|
|
return token, HashToken(token, pepper), nil
|
|
}
|
|
|
|
func HashToken(token, pepper string) string {
|
|
sum := sha256.Sum256([]byte(pepper + token))
|
|
return hex.EncodeToString(sum[:])
|
|
}
|