Package sqlauth

import "github.com/BurntSushi/sqlauth"
Overview
Index

Overview ▾

Variables

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

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.