32 lines
615 B
Go
32 lines
615 B
Go
package models
|
|
|
|
import (
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func MakeHash(password string) (string, error) {
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
return string(bytes), err
|
|
}
|
|
|
|
func (u *User) CheckPassword(password string) bool {
|
|
err := bcrypt.CompareHashAndPassword([]byte(*u.Password), []byte(password))
|
|
return err == nil
|
|
}
|
|
|
|
func (u User) GetID() primitive.ObjectID {
|
|
|
|
return u.ID
|
|
}
|
|
|
|
func (u User) validate() []error {
|
|
|
|
return nil
|
|
}
|
|
|
|
type UserJWT struct {
|
|
ID string `json:"id"`
|
|
Identity string `json:"identity"`
|
|
}
|