stufflog graphql server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
734 B

  1. package models
  2. import (
  3. "errors"
  4. "golang.org/x/crypto/bcrypt"
  5. )
  6. type User struct {
  7. ID string `db:"user_id"`
  8. Name string `db:"name"`
  9. Active bool `db:"active"`
  10. Admin bool `db:"admin"`
  11. Hash []byte `db:"hash"`
  12. }
  13. func (user *User) CheckPassword(password string) bool {
  14. return bcrypt.CompareHashAndPassword(user.Hash, []byte(password)) == nil
  15. }
  16. func (user *User) SetPassword(password string) error {
  17. if len(password) < 6 {
  18. return errors.New("password too short (min: 6)")
  19. }
  20. hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
  21. if err != nil {
  22. return err
  23. }
  24. user.Hash = hash
  25. return nil
  26. }
  27. type UserFilter struct {
  28. UserIDs []string
  29. Active *bool
  30. Admin *bool
  31. Limit *int
  32. }