auth

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package auth issues and validates panel credentials.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidToken = errors.New("invalid token")

Functions

func CheckPassword

func CheckPassword(hash, plain string) bool

func HashPassword

func HashPassword(plain string) (string, error)

HashPassword uses bcrypt, which keeps verification slow enough to make an offline attack on a leaked dump expensive.

func HashToken

func HashToken(token string) string

HashToken digests a node token. Node tokens are high-entropy random strings, so a plain SHA-256 is enough and keeps agent handshakes cheap.

func NewNodeToken

func NewNodeToken() (token, digest, preview string, err error)

NewNodeToken returns a fresh enrolment secret together with the digest stored in the database and a preview safe to show in the UI.

func RandomSecret

func RandomSecret(n int) string

RandomSecret returns a URL-safe random string of the given byte length.

func TokenMatches

func TokenMatches(digest, token string) bool

Types

type Claims

type Claims struct {
	AdminID  string           `json:"sub"`
	Username string           `json:"username"`
	Role     domain.AdminRole `json:"role"`
	jwt.RegisteredClaims
}

type Issuer

type Issuer struct {
	// contains filtered or unexported fields
}

func NewIssuer

func NewIssuer(secret string, ttl time.Duration) *Issuer

func (*Issuer) Issue

func (i *Issuer) Issue(a *domain.Admin) (string, time.Time, error)

func (*Issuer) Parse

func (i *Issuer) Parse(token string) (*Claims, error)

func (*Issuer) TTL

func (i *Issuer) TTL() time.Duration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL