htpasswdauth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

README

HTPassWD Authorizer

The htpasswd authorizer is a simple user-password matcher. It reads its configuration from a htpasswd formatted file.

Example

handler := midgard.StackMiddlewareHandler(
    []defs.Middleware{
        helper.Must(basicauth.New(
            basicauth.WithAuthenticator(helper.Must(
                htpasswdauth.New(htpasswdauth.WithAuthFile('./testwd')))),
            basicauth.WithRealm("testrealm"))),
    },
    http.HandlerFunc(helper.DummyHandler),
)

Be aware that having password hashes accessible to the program potentially exposes them to attackers. Use strong hashing like bcrypt to counteract brute force attacks on the hashes or rainbow tables.

Documentation

Overview

Package htpasswdauth implements the basic auth functionality using a htpasswd file.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyInput = errors.New("input is empty")

ErrEmptyInput is returned when the input is empty.

View Source
var ErrNotInitialized = errors.New("htpasswd auth not initialized")

ErrNotInitialized is returned when the htpasswd authenticator is not initialized.

Functions

func WithAuthFile

func WithAuthFile(fileName string) func(a *HTPassWDAuth) error

WithAuthFile configures the htpasswd file to be read from the filesystem with the given name.

func WithAuthInput

func WithAuthInput(in io.Reader) func(a *HTPassWDAuth) error

WithAuthInput configures the htpasswd file to be read from the given io.Reader.

Types

type HTPassWDAuth

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

HTPassWDAuth holds the htpasswd relevant data.

func New

func New(options ...func(*HTPassWDAuth) error) (*HTPassWDAuth, error)

New creates a new htpasswd authenticator.

func (*HTPassWDAuth) Authorize

func (a *HTPassWDAuth) Authorize(username, password string) (bool, error)

Authorize checks if for a given username the password hash matches the one stored in the used htpasswd file.

Jump to

Keyboard shortcuts

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