155b721438
test / test (push) Has been cancelled
Lay out view, auth, validate, and handlers under internal/web while keeping the cmd/panel API unchanged; update roadmap and changelog for web-split closure. Co-authored-by: Cursor <cursoragent@cursor.com>
21 lines
632 B
Go
21 lines
632 B
Go
package auth
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
)
|
|
|
|
// randomToken returns a URL-safe token with at least nBytes*8 bits of entropy
|
|
// drawn from crypto/rand. Setup and session tokens both use this; the setup
|
|
// token needs >=128 bits (security.md), so callers pass nBytes >= 16.
|
|
//
|
|
// It panics if the system RNG fails: that is unrecoverable and must never be
|
|
// papered over with a weak fallback for a security token.
|
|
func randomToken(nBytes int) string {
|
|
b := make([]byte, nBytes)
|
|
if _, err := rand.Read(b); err != nil {
|
|
panic("crypto/rand failed: " + err.Error())
|
|
}
|
|
return base64.RawURLEncoding.EncodeToString(b)
|
|
}
|