credentials

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package credentials contains the models and functions to manage user credentials.

Index

Constants

View Source
const (
	// TableName is the credential table name in database.
	TableName = "credential"
)

Variables

View Source
var (
	// Credentials is the app password manager.
	Credentials = Manager{}

	// ErrNotFound is returned when a credential record was not found.
	ErrNotFound = errors.New("not found")
)

Functions

func MakePassphrase

func MakePassphrase(size int) (string, error)

MakePassphrase creates a passphrase based on the EFF short word list https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases

Types

type Credential

type Credential struct {
	ID        int           `db:"id" goqu:"skipinsert,skipupdate"`
	UID       string        `db:"uid"`
	UserID    *int          `db:"user_id"`
	Created   time.Time     `db:"created" goqu:"skipupdate"`
	IsEnabled bool          `db:"is_enabled"`
	Name      string        `db:"name"`
	Password  string        `db:"password"`
	Roles     types.Strings `db:"roles"`
}

Credential is an credential record.

func (*Credential) Delete

func (c *Credential) Delete() error

Delete removes a token from the database.

func (*Credential) HashPassword

func (c *Credential) HashPassword(password string) (string, error)

HashPassword returns a new hashed password.

func (*Credential) Save

func (c *Credential) Save() error

Save updates all the password values.

func (*Credential) Update

func (c *Credential) Update(v interface{}) error

Update updates some user values.

type Manager

type Manager struct{}

Manager is a query helper for credential entries.

func (*Manager) Create

func (m *Manager) Create(c *Credential) error

Create insert a new credential in the database.

func (*Manager) GenerateCredential

func (m *Manager) GenerateCredential(userID int) (c *Credential, passphrase string, err error)

GenerateCredential creates a new credential with a random name and passphrase. It returns the Credential instance, the unencrypted passphrase and an error if any.

func (*Manager) GetOne

func (m *Manager) GetOne(expressions ...goqu.Expression) (*Credential, error)

GetOne executes the a select query and returns the first result or an error when there's no result.

func (*Manager) GetUser

func (m *Manager) GetUser(username, password string) (*UserCredential, error)

GetUser attempts to find a user with a matching credential. It returns nil with ErrNotFound if no user and/or password match the query.

func (*Manager) Query

func (m *Manager) Query() *goqu.SelectDataset

Query returns a prepared goqu SelectDataset that can be extended later.

type UserCredential

type UserCredential struct {
	Credential *Credential `db:"c"`
	User       *users.User `db:"u"`
}

UserCredential is the combination of an credential and its user.

Jump to

Keyboard shortcuts

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