package models import ( "errors" "golang.org/x/crypto/bcrypt" ) type User struct { ID string `db:"user_id"` Name string `db:"name"` Active bool `db:"active"` Admin bool `db:"admin"` Hash []byte `db:"hash"` } func (user *User) CheckPassword(password string) bool { return bcrypt.CompareHashAndPassword(user.Hash, []byte(password)) == nil } func (user *User) SetPassword(password string) error { if len(password) < 6 { return errors.New("password too short (min: 6)") } hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { return err } user.Hash = hash return nil } type UserFilter struct { UserIDs []string Active *bool Admin *bool Limit *int }