passwd

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2015 License: MIT Imports: 3 Imported by: 0

README

passwd

GoDoc

Usage

Create a boltdb password database
htbolt -f .boltpasswd -u kelsey
Write some code
package main

import (
	"log"
	"net/http"

	"github.com/boltdb/bolt"
	"github.com/kelseyhightower/htbolt/passwd"
)

func basicAuthHandler(w http.ResponseWriter, r *http.Request) {
	username, password, ok := r.BasicAuth()
	if !ok {
		http.Error(w, "", http.StatusForbidden)
		return
	}

	db, err := bolt.Open(".boltpasswd", 0600, nil)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	err = passwd.Verify(username, password, db)
	if err != nil {
		http.Error(w, "", http.StatusUnauthorized)
		return
	}
}

func main() {
	http.HandleFunc("/", basicAuthHandler)
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Use basic auth with cURL.

curl -i http://kelsey:password@127.0.0.1:8080

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(username, password, comment string, cost int, db *bolt.DB) error

Add adds a new entry to the specified boltdb database. The supplied password is hashed using the bcrypt algorithm before storing in the database.

func Delete

func Delete(username string, db *bolt.DB) error

func Verify

func Verify(username, password string, db *bolt.DB) error

Types

type Entries

type Entries []Entry

func List

func List(db *bolt.DB) (Entries, error)

type Entry

type Entry struct {
	Comment      string
	PasswordHash []byte
	Username     string
}

func NewEntry

func NewEntry(username, password, comment string, cost int) (*Entry, error)

Jump to

Keyboard shortcuts

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