package dao

import (
	"crypto/md5"
	"demo/configs"
	"demo/data/domain"
	"fmt"
)

func Logins(username, password string) (domain.ManageUser, error) {
	user := domain.ManageUser{}
	var err error
	fmt.Println("username", username, "password", password)
	hash := md5.New()
	hash.Write([]byte("kkc-" + password))
	pwd := Md5_KKC(password)
	fmt.Println(configs.Engine)
	//md5摘要
	_, err = configs.Engine.Table("manage_user").Where("username = ?", username).Where("password = ?", pwd).Get(&user)

	if err == nil {
		return user, err
	}
	return domain.ManageUser{}, err
}

func Md5_KKC(str string) string {
	hash := md5.New()
	hash.Write([]byte("kkc-" + str))
	return fmt.Sprintf("%x", hash.Sum(nil))
}
