Help us shape the future of Go! Take the 2026 Go Developer Survey

usermanager

package
v1.3.104 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package usermanager pkg/visor/usermanager/user.go c3-vis-core

Package usermanager pkg/visor/usermanager/user_manager.go c3-vis-core

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadPasswordLen = fmt.Errorf("password length should be between %d and %d chars", minPasswordLen, maxPasswordLen)
	ErrSimplePassword = fmt.Errorf("password must have at least one upper, lower, digit and special character")
	ErrUserExists     = fmt.Errorf("username already exists")
	ErrNameNotAllowed = fmt.Errorf("name not allowed")
	ErrNonASCII       = fmt.Errorf("non-ASCII character found")
)

Errors returned by UserStore.

View Source
var (
	ErrNotLoggedIn       = errors.New("not logged in")
	ErrNotLoggedOut      = errors.New("not logged out")
	ErrBadLogin          = errors.New("incorrect username or password")
	ErrBadSession        = errors.New("session cookie is either non-existent, expired, or ill-formatted")
	ErrMalformedRequest  = errors.New("request format is malformed")
	ErrBadUsernameFormat = errors.New("format of 'username' is not accepted")
	ErrUserNotFound      = errors.New("user is either deleted or not found")
)

Errors associated with user management.

Functions

This section is empty.

Types

type Argon2Params

type Argon2Params struct {
	Time    uint32
	Memory  uint32 // KiB
	Threads uint8
}

Argon2Params are the Argon2id costs a password key was derived with.

type BoltUserStore

type BoltUserStore struct {
	*bbolt.DB
}

BoltUserStore implements UserStore, storing users in a bbolt database file.

func NewBoltUserStore

func NewBoltUserStore(path string) (*BoltUserStore, error)

NewBoltUserStore creates a new BoltUserStore.

func (*BoltUserStore) AddUser

func (s *BoltUserStore) AddUser(user User) error

AddUser adds a new user.

func (*BoltUserStore) RemoveUser

func (s *BoltUserStore) RemoveUser(name string) error

RemoveUser removes a user of given username.

func (*BoltUserStore) SetUser

func (s *BoltUserStore) SetUser(user User) error

SetUser changes an existing user.

func (*BoltUserStore) User

func (s *BoltUserStore) User(name string) (user *User, err error)

User obtains a single user. Returns nil if user does not exist.

type Session

type Session struct {
	SID    uuid.UUID `json:"sid"`
	User   string    `json:"username"`
	Expiry time.Time `json:"expiry"`
}

Session represents a user session.

type SingleUserStore

type SingleUserStore struct {
	UserStore
	// contains filtered or unexported fields
}

SingleUserStore implements UserStore while enforcing only having a single user.

func NewSingleUserStore

func NewSingleUserStore(username string, users UserStore) *SingleUserStore

NewSingleUserStore creates a new SingleUserStore with provided username and UserStore.

func (*SingleUserStore) AddUser

func (s *SingleUserStore) AddUser(user User) error

AddUser adds a new user.

func (*SingleUserStore) RemoveUser

func (s *SingleUserStore) RemoveUser(name string) error

RemoveUser removes a user.

func (*SingleUserStore) SetUser

func (s *SingleUserStore) SetUser(user User) error

SetUser sets an existing user.

func (*SingleUserStore) User

func (s *SingleUserStore) User(name string) (*User, error)

User gets a user.

type User

type User struct {
	Name   string
	PwSalt []byte
	// PwHash is the SHA-256 of the password and salt, kept for users saved
	// before PwKey existed. Such a password is rehashed at the next login.
	PwHash cipher.SHA256
	// PwKey is the Argon2id key of the password and salt under PwParams.
	PwKey    []byte
	PwParams *Argon2Params
}

User represents a user of the hypervisor.

func DecodeUser

func DecodeUser(raw []byte) (*User, error)

DecodeUser decodes the user from bytes.

func (*User) Encode

func (u *User) Encode() ([]byte, error)

Encode encodes the user to bytes.

func (*User) SetName

func (u *User) SetName(name string) bool

SetName checks the provided name, and sets the name if format is valid.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword checks the provided password, and sets the password if format is valid.

func (*User) UpgradePassword

func (u *User) UpgradePassword(password string) bool

UpgradePassword rehashes a verified password saved with the old SHA-256 scheme or older costs, reporting whether the user changed and needs saving. The password is not checked against the current format rules, which it may predate.

func (*User) VerifyPassword

func (u *User) VerifyPassword(password string) bool

VerifyPassword verifies the password input with hash and salt.

type UserManager

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

UserManager manages the users and sessions.

func NewUserManager

func NewUserManager(mLog *logging.MasterLogger, users UserStore, config visorconfig.CookieConfig) *UserManager

NewUserManager creates a new UserManager.

func (*UserManager) Authorize

func (s *UserManager) Authorize(next http.Handler) http.Handler

Authorize is an http middleware for authorizing requests.

func (*UserManager) ChangeAdminPassword

func (s *UserManager) ChangeAdminPassword(oldPassword, newPassword string) error

ChangeAdminPassword updates the password for the "admin" account without requiring an HTTP session — intended for the local RPC path (skywire cli visor hv passwd) which is already privileged. Verifies the old password before writing the new one, enforces the same checkPasswordFormat rules ChangePassword does, and invalidates every active session for the user so old cookies can't be replayed.

func (*UserManager) ChangePassword

func (s *UserManager) ChangePassword() http.HandlerFunc

ChangePassword returns a HandlerFunc for changing the user's password.

func (*UserManager) Close

func (s *UserManager) Close() error

Close closes the underlying db, used for Windows.

func (*UserManager) CreateAccount

func (s *UserManager) CreateAccount() http.HandlerFunc

CreateAccount returns a HandlerFunc for account creation.

func (*UserManager) Login

func (s *UserManager) Login() http.HandlerFunc

Login returns a HandlerFunc for login operations.

func (*UserManager) Logout

func (s *UserManager) Logout() http.HandlerFunc

Logout returns a HandlerFunc of logout operations.

func (*UserManager) SetAdminPassword

func (s *UserManager) SetAdminPassword(newPassword string) error

SetAdminPassword sets the "admin" account password WITHOUT requiring the old one, creating the admin account if it doesn't exist yet. Intended for the local privileged RPC path (skywire cli visor hv passwd --force): a forgotten-password reset, or a first-time set straight from the CLI without the UI's create-account page. Enforces the same checkPasswordFormat rules and invalidates every active session for the user so old cookies can't be replayed.

func (*UserManager) UserExists

func (s *UserManager) UserExists() http.HandlerFunc

UserExists returns a HandlerFunc that reports whether an account has been created. This endpoint is public (no auth required) so the login page can decide whether to show "Create account" or "Log in".

func (*UserManager) UserInfo

func (s *UserManager) UserInfo() http.HandlerFunc

UserInfo returns a HandlerFunc for obtaining user info.

type UserStore

type UserStore interface {
	User(name string) (*User, error)
	AddUser(user User) error
	SetUser(user User) error
	RemoveUser(name string) error
	Close() error
}

UserStore stores users.

Jump to

Keyboard shortcuts

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