pwdauth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package pwdauth provides an authentication service plugin that allows users to authenticate via a email and password.

Index

Constants

View Source
const (
	PluginName   = "auth_pwdauth"
	ProviderName = "password"
)

Variables

View Source
var DefaultHasher = bcryptHasher{}

DefaultHasher calls golang's standard bcrypt functions to hash and compare passwords.

View Source
var TestHasher = testHasher{}

TestHasher is a Hasher that does not hash passwords. It is useful for testing purposes.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID             string
	Email          string
	Name           string
	EmailVerified  bool
	HashedPassword []byte
}

Account contains minimal information needed by the pwdauth plugin to authenticate a user. The application should map it's own user model to this via the AccountFinder interface.

type AccountFinder

type AccountFinder interface {
	// FindAccount looks up a user by their email.
	FindAccount(ctx context.Context, email string) (*Account, error)
}

type Hasher

type Hasher interface {
	// Generate a hashed password from a plaintext password.
	Generate(password []byte) ([]byte, error)

	// Compare a hashed password with a plaintext password.
	Compare(hashedPassword, password []byte) error
}

Interface that allows password hashing to be customized.

type PwdAuthOption

type PwdAuthOption func(*PwdAuthPlugin)

PwdAuthOption allows configuration of the PwdAuthPlugin.

func WithAccountFinder

func WithAccountFinder(f AccountFinder) PwdAuthOption

WithAccountFinder tells the pwdauth plugin how to find user accounts.

func WithHasher

func WithHasher(h Hasher) PwdAuthOption

WithHasher overrides the default hasher used by the PwdAuthPlugin.

type PwdAuthPlugin

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

func Plugin

func Plugin(opts ...PwdAuthOption) *PwdAuthPlugin

Plugin for handling password based authentication.

func (*PwdAuthPlugin) Deps

func (p *PwdAuthPlugin) Deps() []string

From prefab.DependentPlugin.

func (*PwdAuthPlugin) Init

func (p *PwdAuthPlugin) Init(ctx context.Context, r *prefab.Registry) error

From prefab.InitializablePlugin.

func (*PwdAuthPlugin) Name

func (p *PwdAuthPlugin) Name() string

From prefab.Plugin.

Jump to

Keyboard shortcuts

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