auth

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package auth implements the authentication functions for the server.

Index

Constants

View Source
const AdminKeyEnv = "ADMIN_KEY"

AdminKeyEnv is the admin key environment variable to look for.

View Source
const (
	// AdminSessionName is the key name for the admin session cookie.
	AdminSessionName = "kjudge_admin"
)
View Source
const SessionName = "kjudge_user"

SessionName is the kjudge session cookie name.

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(db db.DBContext, c echo.Context) (*models.User, error)

Authenticate tries to resolve an authentication from the context. Might return a nil user with a nil error.

func CheckPassword

func CheckPassword(raw, hashed string) (bool, error)

CheckPassword returns whether the raw password matches the hashed password.

func GeneratePassword

func GeneratePassword(count int) ([]string, error)

GeneratePassword generates random hex passwords of length 8.

func MustAuth

func MustAuth(db *db.DB) echo.MiddlewareFunc

MustAuth returns the middleware that redirects to /login if authentication is not found.

func PasswordHash

func PasswordHash(raw string) ([]byte, error)

PasswordHash hashes a raw string into a hashed password.

func Remove

func Remove(c echo.Context) error

Remove removes the authentication cookie.

func RemoveAdmin

func RemoveAdmin(c echo.Context) error

RemoveAdmin removes the admin cookie session.

func Store

func Store(u *models.User, timeout time.Duration, c echo.Context) error

Store stores the user as a cookie.

Types

type AdminAuth added in v0.7.5

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

AdminAuth hosts the authentication module for admin.

func NewAdmin added in v0.7.5

func NewAdmin() (*AdminAuth, error)

NewAdmin creates a new AdminAuth.

func (*AdminAuth) AuthenticateAdmin added in v0.7.5

func (au *AdminAuth) AuthenticateAdmin(c echo.Context) (bool, error)

AuthenticateAdmin returns whether the context has admin panel access.

func (*AdminAuth) MustAdmin added in v0.7.5

func (au *AdminAuth) MustAdmin(h echo.HandlerFunc) echo.HandlerFunc

MustAdmin is a middleware that ensures admin access.

func (*AdminAuth) SaveAdmin added in v0.7.5

func (au *AdminAuth) SaveAdmin(key string, c echo.Context) error

SaveAdmin saves the admin cookie.

Jump to

Keyboard shortcuts

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