backend barebone done, big chunk of work done
CI / Go (build + vet + test) (push) Canceled after 0s
CI / Web (build + lint) (push) Canceled after 0s

This commit is contained in:
vantablackTea
2026-09-27 19:42:49 +03:00
parent 1a669c948a
commit c79a3cfe68
36 changed files with 2607 additions and 17 deletions
+27
View File
@@ -0,0 +1,27 @@
// Package auth provides cryptographic core for authentication.
package auth
import (
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"fmt"
)
// GenerateRefreshToken generates a new opaque refresh token (raw) and its SHA256 hash.
// The raw token is 32 random bytes hex-encoded; the hash is hex(SHA256(raw)).
func GenerateRefreshToken() (raw, hash string, err error) {
b := make([]byte, 32)
if _, err = rand.Read(b); err != nil {
return "", "", fmt.Errorf("auth: generate refresh token: %w", err)
}
raw = hex.EncodeToString(b)
hash = HashRefreshToken(raw)
return raw, hash, nil
}
// HashRefreshToken returns the SHA256 hash (hex) of the raw refresh token.
func HashRefreshToken(raw string) string {
sum := sha256.Sum256([]byte(raw))
return hex.EncodeToString(sum[:])
}