package models import ( "golang.org/x/crypto/bcrypt" ) type User struct { ModelBase FullName string `json:"full_name"` Username string `json:"username" gorm:"unique"` Password string `json:"password"` //additional optional metadata that Fasten stores with users Picture string `json:"picture"` Email string `json:"email"` //Roles datatypes.JSON `json:"roles"` } func (user *User) HashPassword(password string) error { bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) if err != nil { return err } user.Password = string(bytes) return nil } func (user *User) CheckPassword(providedPassword string) error { err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(providedPassword)) if err != nil { return err } return nil }