auth

package
v0.0.0-...-e4c3b48 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHash         = errors.New("the encoded hash is not in the correct format")
	ErrIncompatibleVersion = errors.New("incompatible version of argon2")
)

Functions

func ComparePasswordAndHash

func ComparePasswordAndHash(password, encodedHash string) (match bool, err error)

func GenerateSessionToken

func GenerateSessionToken() string

func HashPassword

func HashPassword(plainPassword string) (hashedPassword string, err error)

func Login

func Login(conn *pgxpool.Pool) func(ctx context.Context, input *struct {
	Body struct {
		Username string `json:"username"`
		Password string `json:"password"`
	} `json:"body"`
}) (*LoginOutput, error)

func Register

func Register(conn *pgxpool.Pool) func(ctx context.Context, input *struct {
	Body struct {
		Username string `json:"username"`
		Password string `json:"password"`
	} `json:"body"`
}) (*UserOutput, error)

Types

type LoginOutput

type LoginOutput struct {
	SetCookie http.Cookie `header:"Set-Cookie"`
	Body      struct {
		Token    string `json:"token"`
		UserID   int    `json:"user_id"`
		Username string `json:"username"`
	} `json:"body"`
}

type User

type User struct {
	Id       int    `json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type UserOutput

type UserOutput struct {
	Body UserResponse `json:"body"`
}

type UserResponse

type UserResponse struct {
	Id       int    `json:"id"`
	Username string `json:"username"`
}

Jump to

Keyboard shortcuts

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