package
0.0.0-20140401203705-3eca13d6893a
Repository: https://github.com/jimstudt/http-authentication.git
Documentation: pkg.go.dev

# README

auth/htpasswd GoDoc

Authenticate using Apache-style htpasswd files and HTTP Basic Authentication.

htpasswd has supported a number of different password hashing schemes over the decades. Most common and sane ones are supported directly. For some you will need to add another package.

StyleStatus
plainyes+
md5yes
shayes
cryptno (conflicts with plain)
bcryptno (can add with another package)

The standard set of systems will use Plain, Sha, and MD5 systems while filtering out bcrypt. Because of its complexity, bcrypt will be in another package which you can import and add if you need it. Plain accepts both Apache style plain text and nginx style where the password is preceded by {PLAIN}.

Usage

import (
  "github.com/codegangsta/martini"
  "github.com/jimstudt/http-authentication/basic"
  "log"
)

func main() {
  m := martini.Classic()

  pw,err := basic.New("My Realm", "./my-htpasswd-file", htpasswd.DefaultSystems, nil)
  if ( err != nil) {
    log.Fatalf("Unable to read my htpassword file: %s", err.Error())
  }

  // authenticate every request
  m.Use( pw.ServeHTTP)

  // You will also want to call pw.Reload(nil) to reprocess the password file when it changes.

  // You can use pw.ReloadOn( syscall.SIGHUP, nil ) to make it automatically
  // reload on a HUP signal.

  // And those 'nil' arguments are where you pass a function to be notified about illegally 
  // formatted entries, or unsupported hash systems. See the API documents.

  // If you only want to authenticate some requests, then it goes like this...
  //    m.Get("/secure/thing", pw.ServeHTTP, myRealHandler)
  // ... if pw.ServeHTTP does the 401 then your handler will not be called
 
  m.Run()

}

API Documentation

The API is documented using godoc and also available at godoc.org




# Functions

Accept valid MD5 encoded passwords.
Accept any password in the plain text encoding.
Accept valid SHA encoded passwords.
New creates an HtpasswdFile from an Apache-style htpasswd file for HTTP Basic Authentication.
Reject any password encoded using bcrypt.
Reject any MD5 encoded password.
Reject any plain text encoded passoword.
Reject any password encoded as SHA.

# Variables

An array of PasswdParser including all builtin parsers.

# Structs

An HtpasswdFile encompasses an Apache-style htpasswd file for HTTP Basic authentication.

# Interfaces

An EncodedPasswd is created from the encoded password in a password file by a PasswdParser.

# Type aliases

A BadLineHandler is used to notice bad lines in a password file.
Examine an encoded password, and if it is formatted correctly and sane, return an EncodedPasswd which will recognize it.