Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( SHA1Prefix = "{SHA}" BCryp1PRefix = "$2$" BCryp2PRefix = "$2a$" BCryp3PRefix = "$2b$" BCryp4PRefix = "$2x$" BCryp5PRefix = "$2y$" )
View Source
const ( ExtYaml = "YAML" ExtYml = "YML" ExtJson = "JSON" ExtHtpasswd = "htpasswd" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DbManager ¶
type DbManager struct {
// contains filtered or unexported fields
}
DbManager is an opinionated user manager that stores the information on a gorm database
func NewDbManager ¶
func NewDbManager(db *gorm.DB, opts ManagerOpts) (*DbManager, error)
NewDbManager creates an instance of user manager
func (DbManager) AllowLogin ¶
AllowLogin checks if the user provided password is correct for login if no error is returned login is successful
func (DbManager) CreateUser ¶
type ManagerOpts ¶
type ManagerOpts struct {
BcryptDifficulty int
}
type StaticUsers ¶
type StaticUsers struct {
Users []User `yaml:"users"`
}
Example ¶
// load Users from a file userMng, err := FromFile("testdata/users.yaml") panicOnErr(err) // manually add a user userMng.Add("u2", "u2") // check if the user demo (from file) can login isOK := userMng.AllowLogin("demo", "demo") fmt.Printf("user demo can login: %v\n", isOK) // check if the user u2 can login isOK = userMng.AllowLogin("u2", "u2") fmt.Printf("user u2 can login: %v", isOK)
Output: user demo can login: true user u2 can login: true
func FromFile ¶
func FromFile(file string) (*StaticUsers, error)
func (*StaticUsers) Add ¶
func (stu *StaticUsers) Add(user string, pw string)
func (*StaticUsers) AllowLogin ¶
func (stu *StaticUsers) AllowLogin(user string, pw string) bool
Click to show internal directories.
Click to hide internal directories.