goauthenticator

package module
v0.0.0-...-3dd7c34 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

README

goauthenticator

A library for Go to handle authentication and sessions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

type Authenticator struct {
	SessionHandler         SessionHandler
	SaltSize               int
	Iterations             int
	KeyLength              int
	GetUserPasswordAndSalt func(username string) (string, string, error)
}

func NewAuthenticator

func NewAuthenticator(getSessionFromDatabase func(sessionToken string) (Session, error), saveSessionToDatabase func(uid string, session Session) error, redirectURI string, saltSize int, iterations int, keyLength int, getUserPasswordAndSalt func(username string) (string, string, error)) Authenticator

func (*Authenticator) CheckPassword

func (auth *Authenticator) CheckPassword(username string, password string) (bool, error)

CheckPassword checks if the password is correct with the data from the database

func (*Authenticator) CreateSalt

func (auth *Authenticator) CreateSalt() []byte

CreateSalt Create a salt

func (*Authenticator) Hash

func (auth *Authenticator) Hash(password string, salt []byte) []byte

Hash hashes the password and salt using the configuration from the Authenticator object

type Config

type Config struct {
	RedirectURI string
}

type Session

type Session struct {
	SessionToken string `json:"sessionToken" bson:"sessionToken" sql:"sessionToken"`
	Expires      int64  `json:"expires" bson:"expires" sql:"expires"`
	UID          string `json:"uid" bson:"uid"`
}

type SessionHandler

type SessionHandler struct {
	GetSessionFromDatabase func(sessionToken string) (Session, error)
	SaveSessionToDatabase  func(uid string, session Session) error
	Config                 Config
}

func (*SessionHandler) CreateSession

func (sh *SessionHandler) CreateSession(uid string) (Session, error)

func (*SessionHandler) CreateSessionToken

func (sh *SessionHandler) CreateSessionToken() string

func (*SessionHandler) ValidateSession

func (sh *SessionHandler) ValidateSession(next http.Handler) http.Handler

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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