Documentation ¶
Overview ¶
Package credentials contains the models and functions to manage user credentials.
Index ¶
- Constants
- Variables
- func MakePassphrase(size int) (string, error)
- type Credential
- type Manager
- func (m *Manager) Create(c *Credential) error
- func (m *Manager) GenerateCredential(userID int) (c *Credential, passphrase string, err error)
- func (m *Manager) GetOne(expressions ...goqu.Expression) (*Credential, error)
- func (m *Manager) GetUser(username, password string) (*UserCredential, error)
- func (m *Manager) Query() *goqu.SelectDataset
- type UserCredential
Constants ¶
const (
// TableName is the credential table name in database.
TableName = "credential"
)
Variables ¶
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 ¶
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) 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.
type UserCredential ¶
type UserCredential struct { Credential *Credential `db:"c"` User *users.User `db:"u"` }
UserCredential is the combination of an credential and its user.