auth

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: 5 Imported by: 0

Documentation

Overview

Package auth provides in-memory user credentials and role-based action permissions, modeled on FameView (杰控) 用户权限: operators, engineers and admins with gated actions. Credentials are salted SHA-256 hashes; the package depends only on the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Can

func Can(u *User, a Action) bool

Can reports whether user u may perform action a. A nil user, or an unknown action, is denied.

Types

type Action

type Action string

Action names a gated operation.

const (
	ActionViewScreen  Action = "view_screen"  // observe a running screen
	ActionWriteTag    Action = "write_tag"    // write a value to a tag
	ActionEditConfig  Action = "edit_config"  // change project configuration
	ActionManageUsers Action = "manage_users" // add/remove users, set passwords
)

type Role

type Role int

Role is a privilege level. Higher values grant more privilege.

const (
	Operator Role = iota // run screens, write tags
	Engineer             // edit configuration
	Admin                // manage users, everything
)

func (Role) String

func (r Role) String() string

String returns the human-readable role name.

type Store

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

Store is an in-memory set of users keyed by name.

func NewStore

func NewStore() *Store

NewStore returns an empty Store.

func (*Store) AddUser

func (s *Store) AddUser(name, password string, role Role) error

AddUser registers a new user with the given role. The name must be non-empty and not already present. The password is stored as a salted hash.

func (*Store) Authenticate

func (s *Store) Authenticate(name, password string) (*User, bool)

Authenticate returns the user and true when name exists and password matches. The stored hash is compared in constant time; a missing user still performs a hash so timing does not reveal whether the account exists.

func (*Store) SetPassword

func (s *Store) SetPassword(name, password string) error

SetPassword replaces an existing user's password, generating a fresh salt.

type User

type User struct {
	Name string
	Role Role
	// contains filtered or unexported fields
}

User is a named account with a role. Credentials (salt and hash) are unexported and never leave the package.

Jump to

Keyboard shortcuts

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