login

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package login layers login sessions over the auth package: a Manager authenticates credentials, mints a random token per login, and expires sessions after an idle timeout. The clock is injectable so timeout behavior is testable without sleeping. The package depends only on the standard library and auth.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {

	// Now returns the current time; it defaults to time.Now and may be
	// replaced (typically in tests) to drive timeout behavior deterministically.
	Now func() time.Time
	// contains filtered or unexported fields
}

Manager issues and tracks sessions backed by an auth.Store. It is safe for concurrent use.

func NewManager

func NewManager(store *auth.Store, timeout time.Duration) *Manager

NewManager returns a Manager that authenticates against store and expires sessions idle for longer than timeout.

func (*Manager) Current

func (m *Manager) Current(token string) (*auth.User, bool)

Current returns the user behind a live token, refreshing the session. It returns false when the token is unknown or expired.

func (*Manager) Login

func (m *Manager) Login(name, password string) (*Session, error)

Login authenticates name/password against the store and, on success, mints a new session with a random token. It returns an error on bad credentials.

func (*Manager) Logout

func (m *Manager) Logout(token string)

Logout invalidates token. It is a no-op for an unknown token.

func (*Manager) Validate

func (m *Manager) Validate(token string) (*Session, bool)

Validate reports whether token names a live session. A session is live when it has been seen within timeout; Validate then refreshes LastSeen and returns it. An expired (or unknown) token yields false, and an expired session is removed.

type Session

type Session struct {
	Token    string
	User     *auth.User
	Created  time.Time
	LastSeen time.Time
}

Session is an authenticated login. Token is the opaque handle a client presents; LastSeen advances on each successful Validate to keep the session alive within the idle timeout.

Jump to

Keyboard shortcuts

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