mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Create Server/api/constants.go (26 constants) and Server/auth/constants.go (6 constants) for rate limits, timeouts, size limits, and token generation. Replace all inline magic numbers with descriptive names across 9 source files. No behavior changes — same values, just named for contributor readability.
25 lines
620 B
Go
25 lines
620 B
Go
package auth
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
)
|
|
|
|
// GenerateToken returns a cryptographically random 256-bit token encoded as a
|
|
// 64-character lowercase hex string.
|
|
func GenerateToken() (string, error) {
|
|
raw := make([]byte, sessionTokenBytes) // 256 bits
|
|
if _, err := rand.Read(raw); err != nil {
|
|
return "", err
|
|
}
|
|
return hex.EncodeToString(raw), nil
|
|
}
|
|
|
|
// HashToken returns the SHA-256 hex digest of token. Store this hash in the
|
|
// database; never store the plaintext token.
|
|
func HashToken(token string) string {
|
|
sum := sha256.Sum256([]byte(token))
|
|
return hex.EncodeToString(sum[:])
|
|
}
|