password

package
v0.0.0-...-6b846f9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinLength  = 8
	MaxLength  = 99
	DefaultTTL = 24 * 182 * time.Hour
)

constant rules

Variables

View Source
var (
	ErrNilOwnerID       = errors.New("owner id is zero")
	ErrZeroKind         = errors.New("password kind is zero")
	ErrNilPasswordStore = errors.New("password store is nil")
	ErrEmptyPassword    = errors.New("empty password is forbidden")
	ErrPasswordNotFound = errors.New("password not found")
	ErrShortPassword    = errors.New("password is too short")
	ErrLongPassword     = errors.New("password is too long")
	ErrUnsafePassword   = errors.New("password is too unsafe")
	ErrInfeasibleSafety = errors.New("password safety is infeasible with such length and score")
)

Functions

func EvaluatePasswordStrength

func EvaluatePasswordStrength(rawpass []byte, pscore int, data []string) error

EvaluatePasswordStrength evaluates password's strength by checking length, complexity, characters used etc.

func NewRaw

func NewRaw(length int, pscore int, flags GenFlags) (raw []byte)

Types

type GenFlags

type GenFlags uint8
const (
	GFNumber GenFlags = 1 << iota
	GFSpecial
	GFMixCase
	GFDefault = GFNumber | GFMixCase | GFSpecial
)

type Kind

type Kind uint8
const (
	OKUser Kind = 1
	OKApplication
)

password owner kinds

type Manager

type Manager interface {
	Upsert(ctx context.Context, p Password) error
	Get(ctx context.Context, o Owner) (p Password, err error)
	Delete(ctx context.Context, o Owner) error
}

userManager describes the behaviour of a user password manager

func NewManager

func NewManager(store Store) (Manager, error)

NewManager initializes the default user password manager

type Owner

type Owner struct {
	Kind Kind      `db:"kind" json:"kind"`
	ID   uuid.UUID `db:"id" json:"id"`
}

func NewOwner

func NewOwner(k Kind, id uuid.UUID) Owner

type Password

type Password struct {
	Owner
	Hash             []byte    `db:"hash" json:"-"`
	CreatedAt        time.Time `db:"created_at" json:"-"`
	UpdatedAt        time.Time `db:"updated_at" json:"-"`
	ExpireAt         time.Time `db:"expire_at" json:"-"`
	IsChangeRequired bool      `db:"is_change_required" json:"-"`
}

Password object TODO: use byte array instead of slice for password hash

func New

func New(owner Owner, length int, pscore int, flags GenFlags) (p Password, raw []byte, err error)

func NewFromInput

func NewFromInput(o Owner, rawpass []byte, data []string) (p Password, err error)

NewFromInput creates a hash from a given raw password byte slice

func (Password) Compare

func (p Password) Compare(rawpass []byte) bool

Compare tests whether a given plaintext password is valid

func (Password) Validate

func (p Password) Validate() error

SanitizeAndValidate validates password

type PostgreSQLStore

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

func (*PostgreSQLStore) Delete

func (s *PostgreSQLStore) Delete(ctx context.Context, o Owner) (err error)

DeletePolicy deletes a stored password

func (*PostgreSQLStore) Get

func (s *PostgreSQLStore) Get(ctx context.Context, o Owner) (p Password, err error)

Get retrieves a stored password

func (*PostgreSQLStore) Upsert

func (s *PostgreSQLStore) Upsert(ctx context.Context, p Password) (err error)

Upsert stores password ObjectID must be equal to the user's ObjectID

type Store

type Store interface {
	Upsert(ctx context.Context, p Password) error
	Get(ctx context.Context, o Owner) (Password, error)
	Delete(ctx context.Context, o Owner) error
}

func NewMemoryStore

func NewMemoryStore() Store

func NewPostgreSQLStore

func NewPostgreSQLStore(db *pgx.Conn) (Store, error)

Jump to

Keyboard shortcuts

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