auth

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authenticated

func Authenticated(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Authenticated implements the Authenticated(user,pass) function. This accepts a username and password string, and determines if they are authenticated using the users database.

func DeleteUser

func DeleteUser(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

DeleteUser implements the DeleteUser() function. For a privileged user, this will delete a record from the persistent user database. Returns true if the name was deleted, else false if it was not a valid username.

func GetPermission

func GetPermission(user, privilege string) bool

GetPermission returns a boolean indicating if the given username and privilege are valid and set. If the username or privilege does not exist, then the reply is always false.

func GetUser

func GetUser(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

GetUser implements the GetUser() function. This returns a struct defining the persisted information about an existing user in the user database.

func HashString

func HashString(s string) string

HashString converts a given string to it's hash. This is used to manage passwords as opaque objects.

func LoadUserDatabase

func LoadUserDatabase(c *cli.Context) error

loadUserDatabase uses command line options to locate and load the authorized users database, or initialize it to a helpful default.

func Permission

func Permission(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Permission implements the Permission(user,priv) function. It returns a boolean value indicating if the given username has the given permission.

func SetUser

func SetUser(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SetUser implements the SetUser() function. For the super user, this function can be used to update user data in the persistent use database for the Ego web server.

func TokenUser

func TokenUser(t string) string

TokenUser is a helper function that calls the builtin cipher.token() and returns the user field.

func ValidatePassword

func ValidatePassword(user, pass string) bool

ValidatePassword checks a username and password against the database and returns true if the user exists and the password is valid.

func ValidateToken

func ValidateToken(t string) bool

validateToken is a helper function that calls the builtin cipher.validate(). The optional second argument (true) tells the function to generate an error state for the various ways the token was considered invalid.

Types

type DatabaseService

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

func (*DatabaseService) DeleteUser

func (pg *DatabaseService) DeleteUser(name string) error

func (*DatabaseService) Flush

func (pg *DatabaseService) Flush() error

Required interface, but does no work for the Database service.

func (*DatabaseService) ListUsers

func (pg *DatabaseService) ListUsers() map[string]defs.User

func (*DatabaseService) ReadUser

func (pg *DatabaseService) ReadUser(name string, doNotLog bool) (defs.User, error)

func (*DatabaseService) WriteUser

func (pg *DatabaseService) WriteUser(user defs.User) error

type FileService

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

func (*FileService) DeleteUser

func (f *FileService) DeleteUser(name string) error

func (*FileService) Flush

func (f *FileService) Flush() error

func (*FileService) ListUsers

func (f *FileService) ListUsers() map[string]defs.User

func (*FileService) ReadUser

func (f *FileService) ReadUser(name string, doNotLog bool) (defs.User, error)

func (*FileService) WriteUser

func (f *FileService) WriteUser(user defs.User) error

type UserIOService

type UserIOService interface {
	ReadUser(name string, doNotLog bool) (defs.User, error)
	WriteUser(user defs.User) error
	DeleteUser(name string) error
	ListUsers() map[string]defs.User
	Flush() error
}
var AuthService UserIOService

func NewDatabaseService

func NewDatabaseService(connStr, defaultUser, defaultPassword string) (UserIOService, error)

func NewFileService

func NewFileService(userDatabaseFile, defaultUser, defaultPassword string) (UserIOService, error)

Jump to

Keyboard shortcuts

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