sqlauth

package module
Version: v0.0.0-...-2f9e686 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2014 License: Unlicense Imports: 4 Imported by: 0

README

sqlauth is a simple package for managing user authentication that is backed by a database. Emphatically, this package does not handle login forms or redirections. It only exposes a few functions for managing user passwords and authenticating a user's password.

Installation

go get github.com/BurntSushi/sqlauth

Beta

This package is emphatically in BETA. Although most of the API is determined by the gorilla/sessions package, there are still some pieces that may need some changing. (For example, to allow key rotation.)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SqlTableName      = "auth_password"
	SqlCreatePassword = `
	CREATE TABLE IF NOT EXISTS ` + SqlTableName + ` (
		id TEXT NOT NULL,
		hash BYTEA NOT NULL,
		PRIMARY KEY (id, hash)
	)
	`
)

Functions

This section is empty.

Types

type Store

type Store struct {
	*sql.DB
}

func Open

func Open(db *sql.DB) (*Store, error)

func (*Store) Authenticate

func (s *Store) Authenticate(id, password string) (bool, error)

Authenticate returns true if and only if the plain text password given matches the password hash associated with the user. An error is returned if there was a problem finding the user given or if there was an unexpected error comparing the password hashes. If the password does not match, then the error is nil and the bool is false.

func (*Store) Get

func (s *Store) Get(id string) (hash []byte, err error)

Get retrieves the current password hash for the user given.

func (*Store) Set

func (s *Store) Set(id, password string) (cerr error)

Set associates the plain text password given with the user that is uniquely identified by id. The password is hashed with bcrypt. If there is a problem with hashing or with storing the password, an error is returned.

This may be called on a new user.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL