authguard

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2016 License: BSD-2-Clause Imports: 11 Imported by: 3

README

AuthGuard

Package authguard provides a tool for handle and processing login attempts.

It's designed for use with a Gelada, but it can operate as an independent package.

Package DOC.

Documentation

Overview

Package authguard provides a tool for handle and processing login attempts.

It's designed for use with a Gelada (https://github.com/iu0v1/gelada), but it can operate as an independent package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthGuard

type AuthGuard struct {
	// contains filtered or unexported fields
}

AuthGuard - main struct.

func New

func New(o Options) (*AuthGuard, error)

New - init and return new AuthGuard struct.

func (*AuthGuard) Check

func (ag *AuthGuard) Check(username string, req *http.Request) bool

Check by the presence of lockouts. 'true' if there is no locks.

func (*AuthGuard) ClearUntrackedVisitors

func (ag *AuthGuard) ClearUntrackedVisitors()

ClearUntrackedVisitors is used to release the Store data from visitors, who do not have any violations. Store will be synchronized after the process.

Need to reduce the space occupied by the Store.

func (*AuthGuard) Complaint

func (ag *AuthGuard) Complaint(username string, req *http.Request)

Complaint is used to report a failed login attempt.

func (*AuthGuard) GetAllVisitors

func (ag *AuthGuard) GetAllVisitors() []*Visitor

GetAllVisitors return all aviable Visitors.

func (*AuthGuard) GetVisitor

func (ag *AuthGuard) GetVisitor(username string, req *http.Request) (*Visitor, bool)

GetVisitor returns current Visitor.

func (*AuthGuard) Sync

func (ag *AuthGuard) Sync() error

Sync current data with Store immediately.

type BindType

type BindType int

BindType type for BindMethod option.

const (
	BindToNothing       BindType = iota // no bind
	BindToIP                            // bind to user host (IP)
	BindToUsernameAndIP                 // bind to host and username
)

BindMethod types

type LogHandlerFunc

type LogHandlerFunc func(message string, lvl LogLevelType)

LogHandlerFunc type for log handler function

type LogLevelType

type LogLevelType int

LogLevelType declare the level of informatyvity of log message

const (
	LogLevelNone LogLevelType = iota
	LogLevelInfo
	LogLevelError

	LogLevelErrorOnly
)

predefined LogLevelType levels

type Options

type Options struct {
	// Attempts - the number of password attempts.
	Attempts int

	// LockoutDuration - lock duration after the end of password attempts.
	// Seconds.
	LockoutDuration int

	// MaxLockouts - the maximum amount of lockouts, before ban.
	MaxLockouts int

	// BanDuration - duration of ban.
	// Seconds.
	BanDuration int

	// AttemptsResetDuration - time after which to reset the number of attempts.
	// Seconds.
	AttemptsResetDuration int

	// LockoutsResetDuration - time after which to reset the number of lockouts.
	LockoutsResetDuration int

	// BindMethod - visitor binding type. Only IP or IP + username.
	BindMethod BindType

	// SyncAfter - sync data with the Store file after X updates.
	SyncAfter int

	// Store - place for store user data.
	// Filepath.
	//
	// If Store == "::memory::", then Gelada does not place the data in the file
	// and store everything in memory.
	Store string

	// Exceptions - Hosts(IP) whitelist.
	Exceptions []string

	// LogLevel provides the opportunity to choose the level of
	// information messages.
	// Each level includes the messages from the previous level,
	// except LogLevelErrorOnly.
	// LogLevelNone       - no messages // 0
	// LogLevelInfo       - info        // 1
	// LogLevelError      - error       // 2
	// LogLevelErrorOnly  - only errors // 3
	//
	// Default: LogLevelNone.
	LogLevel LogLevelType

	// LogDestination provides the opportunity to choose the own
	// destination for log messages (errors, info, etc).
	//
	// Default: 'os.Stdout'.
	LogDestination io.Writer

	// LogHandler takes log messages to bypass the internal
	// mechanism of the message processing
	//
	// If LogHandler is selected - all log settings will be ignored.
	LogHandler LogHandlerFunc

	// ProxyIPHeaderName - http header name for handle user IP behind proxy
	ProxyIPHeaderName string
}

Options - structure, which is used to configure authguard.

type Visitor

type Visitor struct {
	Username  string
	Host      string
	UserAgent string

	Attempts int
	Lockouts int

	Ban bool

	ResetAttemptsAfter time.Time
	ResetLockoutsAfter time.Time
	LockUntil          time.Time
	// contains filtered or unexported fields
}

Visitor contain info about the current user and provide some helper methods.

func (*Visitor) LockDate

func (v *Visitor) LockDate() time.Time

LockDate - return the raw time until the lockouts ends.

func (*Visitor) LockRemainingTime

func (v *Visitor) LockRemainingTime() int

LockRemainingTime - return the time until the lockouts ends, in seconds.

func (*Visitor) Reset

func (v *Visitor) Reset()

Reset all attempts, lockouts and bans.

Jump to

Keyboard shortcuts

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