WWWShop/wwwshop/model/user/user.go

21 lines
463 B
Go
Raw Normal View History

package user
import (
"golang.org/x/crypto/bcrypt"
)
type User struct {
Id int64 `json:"id"`
Username string `json:"username"`
PasswordHash string `json:"password_hash"`
}
func New(id int64, username string, password_hash string) User {
return User{id, username, password_hash}
}
func (self User) CheckPassword(password string) bool {
err := bcrypt.CompareHashAndPassword([]byte(self.PasswordHash), []byte(password))
return err == nil
}