Documentation
¶
Index ¶
- Variables
- func HashPassword(password string) ([]byte, error)
- func ValidatePassword(hash []byte, password string) error
- type Auth
- type TokenManager
- type User
- type UserPassAuth
- func (a *UserPassAuth) AddUser(user *User) error
- func (a *UserPassAuth) DeleteUser(username string) error
- func (a *UserPassAuth) GetUser(username string) (*User, error)
- func (a *UserPassAuth) Login(username, password string) (string, error)
- func (a *UserPassAuth) SetPassword(username, password string) error
- func (a *UserPassAuth) UpdateUser(user *User) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrUserAlreadyExists indicates the user already exists. ErrUserAlreadyExists = errors.New("User already exists") // ErrUserDoesNotExist indicates the given username does not exist. ErrUserDoesNotExist = errors.New("User does not exist") // ErrUsernameEmpty indicates the given username was empty. ErrUsernameEmpty = errors.New("Username cannot be empty") // ErrPasswordTooShort indicates the given password was too short. ErrPasswordTooShort = errors.New("Password must be at least 6 characters long") )
Functions ¶
func HashPassword ¶
HashPassword creates a secure hash of a password for storage.
func ValidatePassword ¶
ValidatePassword checks the given plaintext password against the stored hash.
Types ¶
type Auth ¶
type Auth interface { // Login validates the given credentials and if successful, generates a token. Login(username, password string) (string, error) // AddUser adds a new user. AddUser(user *User) error // UpdateUser updates an existing user. UpdateUser(user *User) error // SetPassword sets a password for a user. SetPassword(username, password string) error // GetUser gets a User object. GetUser(username string) (*User, error) // DeleteUser deletes a User. DeleteUser(username string) error }
Auth provides authentication.
type TokenManager ¶
type TokenManager struct {
// contains filtered or unexported fields
}
TokenManager object.
func NewTokenManager ¶
func NewTokenManager(key []byte, ttl time.Duration) *TokenManager
NewTokenManager returns a new TokenManager.
type User ¶
type User struct { Username string `json:"username,omitempty"` Disabled bool `json:"disabled,omitempty"` Admin bool `json:"admin,omitempty"` }
User object.
type UserPassAuth ¶
type UserPassAuth struct {
// contains filtered or unexported fields
}
UserPassAuth implements basic user password authentication using a BoltDB backend.
func NewUserPassAuth ¶
func NewUserPassAuth(address string, tm *TokenManager) (*UserPassAuth, error)
NewUserPassAuth creates a new UserPassAuth object.
func (*UserPassAuth) AddUser ¶
func (a *UserPassAuth) AddUser(user *User) error
AddUser adds a new user.
func (*UserPassAuth) DeleteUser ¶
func (a *UserPassAuth) DeleteUser(username string) error
DeleteUser deletes a User.
func (*UserPassAuth) GetUser ¶
func (a *UserPassAuth) GetUser(username string) (*User, error)
GetUser gets a User object.
func (*UserPassAuth) Login ¶
func (a *UserPassAuth) Login(username, password string) (string, error)
Login validates the given credentials and if successful, generates a token.
func (*UserPassAuth) SetPassword ¶
func (a *UserPassAuth) SetPassword(username, password string) error
SetPassword sets a password for a user.
func (*UserPassAuth) UpdateUser ¶
func (a *UserPassAuth) UpdateUser(user *User) error
UpdateUser updates an existing user.
Click to show internal directories.
Click to hide internal directories.