Version: v0.8.1 Latest Latest

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

Go to latest
Published: Jan 12, 2016 License: Apache-2.0 Imports: 11 Imported by: 0



Package basicauth implements HTTP Basic Authentication.



This section is empty.


This section is empty.


This section is empty.


type BasicAuth

type BasicAuth struct {
	Next     middleware.Handler
	SiteRoot string
	Rules    []Rule

BasicAuth is middleware to protect resources with a username and password. Note that HTTP Basic Authentication is not secure by itself and should not be used to protect important assets without HTTPS. Even then, the security of HTTP Basic Auth is disputed. Use discretion when deciding what to protect with BasicAuth.

func (BasicAuth) ServeHTTP

func (a BasicAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP implements the middleware.Handler interface.

type PasswordMatcher added in v0.7.6

type PasswordMatcher func(pw string) bool

PasswordMatcher determines whether a password matches a rule.

func GetHtpasswdMatcher added in v0.7.6

func GetHtpasswdMatcher(filename, username, siteRoot string) (PasswordMatcher, error)

GetHtpasswdMatcher matches password rules.

func PlainMatcher added in v0.7.6

func PlainMatcher(passw string) PasswordMatcher

PlainMatcher returns a PasswordMatcher that does a constant-time byte-wise comparison.

type Rule

type Rule struct {
	Username  string
	Password  func(string) bool
	Resources []string

Rule represents a BasicAuth rule. A username and password combination protect the associated resources, which are file or directory paths.

Source Files

Jump to

Keyboard shortcuts

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