auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package auth is KnightLoader's optional password lock. Self-hosted means the instance often sits on a LAN where "anyone who can reach the port" is not the same as "anyone who should control the downloads".

It is off by default: a fresh install behaves exactly as before until a password is set. Sessions are signed cookies rather than a server-side table, so a restart does not log everyone out.

Index

Constants

View Source
const CookieName = "kl_session"

CookieName is the session cookie the browser sends back.

View Source
const SessionTTL = 30 * 24 * time.Hour

SessionTTL is how long a login lasts.

Variables

View Source
var (
	// ErrWrongPassword is returned when the supplied password does not match.
	ErrWrongPassword = errors.New("wrong password")
	// ErrTooShort rejects a password that is not worth having.
	ErrTooShort = errors.New("the password must be at least 8 characters")
)

Functions

This section is empty.

Types

type Guard

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

Guard holds the password and signs sessions.

func Open

func Open(dir string) (*Guard, error)

Open loads (or creates) the lock state in dir.

func (*Guard) Check

func (g *Guard) Check(password string) bool

Check verifies a password against the stored hash.

func (*Guard) Enabled

func (g *Guard) Enabled() bool

Enabled reports whether a password is required.

func (*Guard) Issue

func (g *Guard) Issue() string

Issue returns a session token valid for SessionTTL.

func (*Guard) SetPassword

func (g *Guard) SetPassword(current, next string) error

SetPassword sets, changes or (with an empty next) removes the password. When a password is already set, the current one has to be supplied — otherwise anyone with an open session could silently lock the owner out.

func (*Guard) Valid

func (g *Guard) Valid(token string) bool

Valid reports whether a token is well-formed, correctly signed and unexpired.

Jump to

Keyboard shortcuts

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