users

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2017 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const RecoveryAdminName = "_admin"
View Source
const RecoveryPeriod = 30 * time.Minute
View Source
const SessionLifetime = 90 * 24 * time.Hour

Variables

View Source
var ErrAuthenticationFailed = errors.New("authentication failed, incorrect username or password")
View Source
var ErrPasswordTooCommon = errors.New("password is too common")
View Source
var ErrPasswordTooLong = fmt.Errorf("password exceeds maximum length %d", maxPasswordLength)
View Source
var ErrPasswordTooRepetitive = errors.New("password is too repetitive")
View Source
var ErrPasswordTooShort = fmt.Errorf("password does not meet minimum length %d", minPasswordLength)
View Source
var ErrUsernameTooLong = errors.New("username too long")
View Source
var ErrUsernameTooShort = errors.New("username too short")

Functions

func InitCommonPasswords

func InitCommonPasswords(conf config.Config) error

InitCommonPasswords reads in the configured list of common passwords.

func NewContext

func NewContext(ctx context.Context, u User) context.Context

NewContext returns a new Context includign the given User.

func NewOwnerContext

func NewOwnerContext(ctx context.Context, u User) context.Context

NewOwnerContext returns a new Context includign the given User.

func RecoveryMode

func RecoveryMode() (string, error)

RecoveryMode initializes recovery mode, creating a temporary admin account, and returning the password to the account.

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword against the password rules.

func ValidateUsername

func ValidateUsername(name string) error

Types

type AccessLevel

type AccessLevel uint8
const (
	LevelAnon AccessLevel = iota
	LevelGuest
	LevelUser
	LevelAdmin
	LevelRecovery
)

func ParseAccessLevel

func ParseAccessLevel(in string) AccessLevel

func (AccessLevel) String

func (al AccessLevel) String() string

type Password

type Password struct {
	Version uint8
	Hash    []byte
	Salt    []byte
}

Password encapsulates all of the data necessary to hash and validate passwords securely.

func NewPassword

func NewPassword(password string) (*Password, error)

NewPassword creates a new salt and hash for the given password, using the current latest password version.

func RandomPassword

func RandomPassword(length int) (string, *Password, error)

RandomPassword generates a random password of the given length using a CPRNG.

func (Password) NeedsUpdate

func (p Password) NeedsUpdate() bool

NeedsUpdate returns true if the password scheme is out of date and needs updating. Note that this cannot be done automatically, because we can't get the plaintext password from the old hash to generate a new one.

func (Password) Verify

func (p Password) Verify(input string) (bool, error)

Verify that the given password string matches this hash.

type Session

type Session struct {
	ID      uuid.UUID `json:"id"`
	UserID  uuid.UUID `json:"-"`
	Expires time.Time
	Key     *Password
	Secret  string `json:"-"`
}

type User

type User struct {
	ID          uuid.UUID   `json:"id" xml:"id,attr" bson:"_id"`
	Username    string      `json:"username" storm:"unique"`
	DisplayName string      `json:"name"`
	Password    *Password   `json:"password,omitempty" xml:"-"`
	Access      AccessLevel `json:"access"`
	Sessions    []*Session  `json:"sessions,omitempty" xml:"-"`
}

func AuthenticateAdmin

func AuthenticateAdmin(password string) (User, error)

AuthenticateAdmin authenticates the given password against the temporary admin account, if any.

func FromContext

func FromContext(ctx context.Context) (User, bool)

FromContext returns the authenticated User in the given Context, if it is set.

func New

func New(username string) User

func OwnerFromContext

func OwnerFromContext(ctx context.Context) (User, bool)

OwnerFromContext returns the owning User in the given Context, if it is set.

func (*User) CleanSessions

func (u *User) CleanSessions()

func (*User) NewSession

func (u *User) NewSession() (session Session, err error)

func (*User) ValidateSession

func (u *User) ValidateSession(sessID uuid.UUID, key string) bool

Jump to

Keyboard shortcuts

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