auth

package
v0.0.0-...-95c6f9f Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RoleViewChats = &Role{
		ID:          1,
		Description: "Allows user to view server chats",
	}
	RoleMutePlayers = &Role{
		ID:          2,
		Description: "Allows user to mute players",
	}
	RoleBanPlayers = &Role{
		ID:          3,
		Description: "Allows user to ban players",
	}
	RoleExpungeHistory = &Role{
		ID:          4,
		Description: "Allows user to expunge items from players' moderation history",
	}
	RoleManageUsers = &Role{
		ID:          5,
		Description: "Allows user to add and remove panel users",
	}
)

Roles

Functions

func DecodeSession

func DecodeSession(token string) (int, string, error)

Types

type Auth

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

func NewAuth

func NewAuth(params *Params, tokenDuration time.Duration) *Auth

func (*Auth) EncodeSession

func (a *Auth) EncodeSession(id int, secret string) string

func (*Auth) HashMatches

func (a *Auth) HashMatches(password string, hashedPassword string) (bool, error)

func (*Auth) HashPassword

func (a *Auth) HashPassword(password string) (string, error)

func (*Auth) NewSession

func (a *Auth) NewSession(
	user *User,
	userAgent string,
	ipAddress string,
) (*Session, string, error)

TODO: This is revolting, but the caller will need to persist it themselves and then generate their own token

type Params

type Params struct {
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	SaltLength  uint32
	KeyLength   uint32
}

type Role

type Role struct {
	ID          int    `json:"id"`
	Description string `json:"description"`
}

type Session

type Session struct {
	Id           int
	UserId       int
	HashedSecret string
	UserAgent    string
	IpAddress    string
	CreatedAt    time.Time
	ExpiresAt    time.Time
}

type User

type User struct {
	Id             int
	Username       string
	HashedPassword string
	CreatedAt      time.Time
	LastLogin      time.Time
}

Jump to

Keyboard shortcuts

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