27 lines
550 B
Go
27 lines
550 B
Go
package models
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"fmt"
|
|
"main/configs"
|
|
)
|
|
|
|
type User struct {
|
|
ID int `json:"id" gorm:"primary_key"`
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
Password string `json:"-"`
|
|
Slat string `json:"-"`
|
|
}
|
|
|
|
func init() {
|
|
configs.ORMDB().AutoMigrate(&User{})
|
|
}
|
|
|
|
// 驗證用戶密碼
|
|
func (user *User) CheckPassword(password string) bool {
|
|
return user.Password == fmt.Sprintf("%x", md5.Sum([]byte(password+user.Slat)))
|
|
}
|