Documentation ¶
Index ¶
- Constants
- Variables
- func InitCommonPasswords(conf config.Config) error
- func NewContext(ctx context.Context, u User) context.Context
- func NewOwnerContext(ctx context.Context, u User) context.Context
- func RecoveryMode() (string, error)
- func ValidatePassword(password string) error
- func ValidateUsername(name string) error
- type AccessLevel
- type Password
- type Session
- type User
Constants ¶
const RecoveryAdminName = "_admin"
const RecoveryPeriod = 30 * time.Minute
const SessionLifetime = 90 * 24 * time.Hour
Variables ¶
var ErrAuthenticationFailed = errors.New("authentication failed, incorrect username or password")
var ErrPasswordTooCommon = errors.New("password is too common")
var ErrPasswordTooLong = fmt.Errorf("password exceeds maximum length %d", maxPasswordLength)
var ErrPasswordTooRepetitive = errors.New("password is too repetitive")
var ErrPasswordTooShort = fmt.Errorf("password does not meet minimum length %d", minPasswordLength)
var ErrUsernameTooLong = errors.New("username too long")
var ErrUsernameTooShort = errors.New("username too short")
Functions ¶
func InitCommonPasswords ¶
InitCommonPasswords reads in the configured list of common passwords.
func NewContext ¶
NewContext returns a new Context includign the given User.
func NewOwnerContext ¶
NewOwnerContext returns a new Context includign the given User.
func RecoveryMode ¶
RecoveryMode initializes recovery mode, creating a temporary admin account, and returning the password to the account.
func ValidatePassword ¶
ValidatePassword against the password rules.
func ValidateUsername ¶
Types ¶
type AccessLevel ¶
type AccessLevel uint8
const ( LevelAnon AccessLevel = iota LevelGuest LevelUser LevelAdmin LevelRecovery )
func ParseAccessLevel ¶
func ParseAccessLevel(in string) AccessLevel
func (AccessLevel) String ¶
func (al AccessLevel) String() string
type Password ¶
Password encapsulates all of the data necessary to hash and validate passwords securely.
func NewPassword ¶
NewPassword creates a new salt and hash for the given password, using the current latest password version.
func RandomPassword ¶
RandomPassword generates a random password of the given length using a CPRNG.
func (Password) NeedsUpdate ¶
NeedsUpdate returns true if the password scheme is out of date and needs updating. Note that this cannot be done automatically, because we can't get the plaintext password from the old hash to generate a new one.
type User ¶
type User struct { ID uuid.UUID `json:"id" xml:"id,attr" bson:"_id"` Username string `json:"username" storm:"unique"` DisplayName string `json:"name"` Password *Password `json:"password,omitempty" xml:"-"` Access AccessLevel `json:"access"` Sessions []*Session `json:"sessions,omitempty" xml:"-"` }
func AuthenticateAdmin ¶
AuthenticateAdmin authenticates the given password against the temporary admin account, if any.
func FromContext ¶
FromContext returns the authenticated User in the given Context, if it is set.
func OwnerFromContext ¶
OwnerFromContext returns the owning User in the given Context, if it is set.
func (*User) CleanSessions ¶
func (u *User) CleanSessions()