Documentation ¶
Index ¶
- Constants
- func Base6424(src string) string
- func GenString(size int) string
- func GenerateDovecotPassword(password, salt string, rounds int) string
- type Alias
- type Aliases
- type DBM
- func (db *DBM) AddResetToken(user *User, duration time.Duration) (string, error)
- func (db *DBM) AddSite(name string) (int64, error)
- func (db *DBM) AddUser(username, password, email, first, last, data, tokens string, cost int) (*User, error)
- func (db *DBM) ClearFlag(key string) error
- func (db *DBM) Connect(name string) error
- func (db *DBM) ConnectionString() string
- func (db *DBM) Create(name string) error
- func (db *DBM) DatabaseExists(name string) bool
- func (db *DBM) DeleteResetToken(key string) error
- func (db *DBM) Drop(name string) error
- func (db *DBM) GetAlias(alias string) (string, error)
- func (db *DBM) GetAliasesForUser(u *User) (*Aliases, error)
- func (db *DBM) GetFlag(key string) bool
- func (db *DBM) GetSitesForUser(u *User) error
- func (db *DBM) GetUser(id int64) (*User, error)
- func (db *DBM) GetUserByName(name string) (*User, error)
- func (db *DBM) GetUserForReset(key string) (*User, error)
- func (db *DBM) GetUsers(match string) (*Users, error)
- func (db *DBM) GetVar(key string) string
- func (db *DBM) InitDatabase() error
- func (db *DBM) InitMailTables() error
- func (db *DBM) PurgeResetTokens() error
- func (db *DBM) RemoveAlias(alias string) error
- func (db *DBM) RemoveAliases(target string) error
- func (db *DBM) RemoveSite(id int64) error
- func (db *DBM) RemoveSiteByName(name string) error
- func (db *DBM) RemoveUser(id int64) error
- func (db *DBM) RemoveUserByName(name string) error
- func (db *DBM) RemoveVar(key string) error
- func (db *DBM) SaveUser(u *User) error
- func (db *DBM) SearchAliases(match string) (*Aliases, error)
- func (db *DBM) SearchSites(match string) (*Sites, error)
- func (db *DBM) SetAlias(alias, target string) error
- func (db *DBM) SetEmail(u *User) error
- func (db *DBM) SetFlag(key string, flag bool) error
- func (db *DBM) SetVar(key, value string) error
- type Group
- type Site
- type Sites
- type User
- func (u *User) AcceptablePassword(password string) bool
- func (u *User) CheckPassword(password string) bool
- func (u *User) CompareDovecotHashAndPassword(password string) bool
- func (u *User) GetCost() int
- func (u *User) GetRounds() int
- func (u *User) SetDovecotPassword(password string, rounds int)
- func (u *User) SetPassword(password string, cost int) error
- func (u *User) SplitPasswordElements() []string
- type Users
Constants ¶
const DefaultName = "accounts"
Variables ¶
This section is empty.
Functions ¶
func GenerateDovecotPassword ¶ added in v0.4.0
GenerateDovecotPassword creates a Dovecot-compatible password with the SHA512-CRYPT algorithm prefix.
Types ¶
type Aliases ¶ added in v0.6.0
type Aliases struct {
List []Alias `json:"aliases"`
}
Aliases container.
type DBM ¶
DBM is a DB manager for user accounts and groups.
func (*DBM) AddResetToken ¶ added in v0.9.4
AddResetToken creates a reset token with an expiry for an account, then returns the human-readable hash.
func (*DBM) AddUser ¶
func (db *DBM) AddUser(username, password, email, first, last, data, tokens string, cost int) (*User, error)
AddUser creates a new User. This may fail.
func (*DBM) ConnectionString ¶
func (*DBM) DatabaseExists ¶
DatabaseExists checks for the existence of the actual database.
func (*DBM) DeleteResetToken ¶ added in v0.9.4
DeleteResetToken invalidates a reset token. Call when resetting a password.
func (*DBM) GetAliasesForUser ¶ added in v0.9.4
GetAliasesForUser returns all addresses pointing to this user's address. This call is specific to mail mode.
func (*DBM) GetSitesForUser ¶ added in v0.4.0
GetSitesForUser fills the Sites field in the User struct.
func (*DBM) GetUserByName ¶
GetUserByName for when you don't have an ID.
func (*DBM) GetUserForReset ¶ added in v0.9.4
GetUserForReset returns a User if the token is valid.
func (*DBM) GetUsers ¶ added in v0.2.0
GetUsers retrieves users, sorted by ID, optionally containing a keyword.
func (*DBM) InitDatabase ¶
InitDatabase creates the tables, functions and triggers required for the full account system.
func (*DBM) InitMailTables ¶ added in v0.6.0
InitMailTables for mail mode.
func (*DBM) PurgeResetTokens ¶ added in v0.9.4
PurgeResetTokens deletes the oldest unused and expired tokens.
func (*DBM) RemoveAlias ¶ added in v0.6.0
RemoveAlias deletes an alias.
func (*DBM) RemoveAliases ¶ added in v0.6.0
RemoveAliases deletes all aliases with the same target.
func (*DBM) RemoveSite ¶ added in v0.8.0
RemoveSite by ID.
func (*DBM) RemoveSiteByName ¶ added in v0.8.0
RemoveSiteByName for when that's more convenient.
func (*DBM) RemoveUser ¶ added in v0.8.0
RemoveUser by ID.
func (*DBM) RemoveUserByName ¶ added in v0.8.0
RemoveUserByName for when that's needed.
func (*DBM) SaveUser ¶
UpdateUser saves an existing user by ID. Potentially slower than updating individual columns, and needs changing if the schema changes.
func (*DBM) SearchAliases ¶ added in v0.6.0
SearchAliases finds aliases or targets containing the match string. Leave blank to list everything.
func (*DBM) SearchSites ¶ added in v0.8.0
SearchSites finds sites containing the match string. Leave blank to list everything.
func (*DBM) SetAlias ¶ added in v0.6.0
SetAlias creates or updates a new alias pointing to an existing target address (which may itself be an alias).
type Site ¶ added in v0.4.0
type Site struct { ID int64 `json:"id"` Name string `json:"name"` Created time.Time `json:"created"` Groups map[string]Group `json:"groups"` }
Site or domain.
type User ¶
type User struct { // ID of user in the database. ID int64 `json:"id"` // Username to log in with. Username string `json:"username"` // Password for user account. Password string `json:"password"` // Salt for the password. Salt string `json:"salt"` // Email to verify account or reset password. Email string `json:"email"` // Created timestamp. Created time.Time `json:"created"` // First name of user (optional). First string `json:"first"` // Last name of user (optional). Last string `json:"last"` // Data for the account. JSON field for all the customising you need. Data string `json:"data"` // Tokens is meant to store any authentication tokens required for external sites. Tokens string `json:"token"` // Sites the user is a member of. Sites []string // Locked accounts can't log in. Locked bool `json:"locked"` // Admin for the whole system if true. Admin bool `json:"admin"` }
User account structure holds basic login and personal information.
func (*User) AcceptablePassword ¶ added in v0.9.1
AcceptablePassword does some superficial checking of a potential password. It will fail the test if it's too short, contains user details or is all numbers. Further policies have to be applied outside of this function.
func (*User) CheckPassword ¶
CheckPassword against the account's hash.
func (*User) CompareDovecotHashAndPassword ¶ added in v0.4.0
CompareDovecotHashAndPassword for systems where getting bcrypt support in Dovecot is a pain.
func (*User) SetDovecotPassword ¶ added in v0.4.0
SetDovecotPassword sets a Dovecot-compatible password for the user.
func (*User) SetPassword ¶
SetPassword generates a new salt and sets the password.
func (*User) SplitPasswordElements ¶ added in v0.9.1
SplitPasswordElements splits the stored password hash and returns it if it fits any supported pattern (4 elements for bcrypt, 5 for Dovecot).