htpasswd

package module
v0.0.0-...-492dd98 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: MIT Imports: 9 Imported by: 0

README

Htpasswd Authentication

Htpasswd is a go package for reading and authenticating using htpasswd files.

Installation

go get -u github.com/ctxswitch/htpasswd

Quick Start

h, err := htpasswd.Open('/path/to/.htpasswd')
h.Authenticate('username', 'password')

// At any point you can reload the users if anything has changed
h.Reload()

At some point a process that reloads the contents at a specified check interval will be added, but it has not been implimented. It will look like this:

h, err := htpasswd.Open('/path/to/.htpasswd')
// Set the check interval for 30 seconds
h.CheckInterval = 30
// Start the process to automatically reload the file at the specified check interval
h.AutoReload()

Development Status

Though the standard interface will be stable, the project is new and should not yet be considered stable for production use.

Contributing

Contributions are encouraged. In the interest of fostering an open and welcoming environment, we pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// CheckInterval is the number of seconds between checks.
	// If automatic reloading is enabled, this value is used as the wait time
	// between checks.  If disabled, this value has no effect.
	CheckInterval int64
	// contains filtered or unexported fields
}

File reads htpasswd files and provides authentication

As returned by Open, a File reads in an htpasswd file searching for bcrypt hashed passwords that conform to the published formats: https://httpd.apache.org/docs/2.4/misc/password_encryptions.html CheckInterval can be customized before the first call to AutoReload to specify the wait interval between reload checks. If CheckInterval is not set, AutoReload will not be run.

func Open

func Open(p string) (*File, error)

Open returns a new File populated with users from the specified htpasswd file path.

func (*File) Authenticate

func (h *File) Authenticate(u string, p string) bool

Authenticate checks a user and password against the hashed value in the users map.

func (*File) Reload

func (h *File) Reload() error

Reload checks the modification time of the htpasswd file and reads the file in again if it has changed

Jump to

Keyboard shortcuts

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